如何获取仅具有填充值的属性? [英] How do I get properties that ONLY have populated values?

查看:48
本文介绍了如何获取仅具有填充值的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取仅包含填充值的属性?

How do I get properties that ONLY have populated values?

例如,如果我跑步

Get-QADUser -Identity "SomeOne" -IncludeAllProperties

输出当然包括..所有属性,包括有值和没有值的属性.我想要一个只有值的属性列表.一般是怎么做的?

the output would of course include.. all properties, including those with and those without values. I want a listing of properties with values only. How is it done generally speaking?

这不仅限于 Quest Cmdlets,我仅以 Get-QADUser 为例.

This wouldn't be restricted to Quest Cmdlets, I only use Get-QADUser as an example.

推荐答案

您可以尝试使用名为 PSObject 的 PowerShell 对象的内置(隐藏)属性,其中包括名为 的属性属性,即父对象上所有属性的列表.

You could try using the built-in (hidden) property of PowerShell objects called PSObject, which includes a property called Properties, i.e. a list of all properties on the parent object.

举个例子也许更容易.以 Get-Process 为例,一个进程可以有许多带有或不带有值的属性(属性).为了只获得具有值的值,您可以这样做:

Maybe easier with an example. Take Get-Process... a process can have many attributes (properties) with or without values. In order to get just the ones with values you do this:

(Get-Process | Select -First 1).PSObject.Properties | ?{$_.Value -ne $null} | FT Name,Value

请注意,我仅将其限制为 Get-Process 返回的第一个进程.然后我们获取在该对象上定义的所有属性,过滤 Value 不为空的地方,然后只显示这些属性的 NameValue.

Note that I limited this to just the first process returned by Get-Process. We then get all the properties defined on that object, filtering where Value is not null and then displaying just the Name and Value for those properties.

这篇关于如何获取仅具有填充值的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆