在PowerShell中对属性值返回true/false,而不是该值 [英] Return true/false on property value in PowerShell, not the value

查看:521
本文介绍了在PowerShell中对属性值返回true/false,而不是该值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PowerShell的Get-ADuser提取一些选定的属性(比基本属性多,但少于select *).

I'm using PowerShell's Get-ADuser to pull some curated attributes (more than basic but less the select *).

没什么特别的,基本上是用户创建的时间,上次登录(我认为是该用户的必需表达)以及其他一些内容.大多数只是简单的属性返回.但是,我也想检查是否存在UserSmmimeCert.

Nothing too special, basically user created time, last log-on (required expression for that one I think), and a few others. Most are just simple property attribute returns. However, I also want to check for the presence UserSmmimeCert.

它本身可以被拉出,但是返回值是SMIME键的值,因此它长得令人难以置信.我不需要钥匙.我只想返回true/false(如果该字段存在或不存在).如果我想要的唯一字段是UserSmimeCertificate(在下面),我有办法做到这一点,但是我希望它与我要提取的其他值一起使用.

By itself, it can be pulled, but the return is the value of the SMIME key, so it's hideously long. I don't need the key; I just want a return of true/false if the field is present or not. I have a way to do this if the ONLY field I want is the UserSmimeCertificate (below), but I want it along side the other values I am pulling.

Get-ADUser -Identity $user -Properties userSmimeCertificate | select -ExpandProperty userSmimeCertificate) -is [System.Array]

是的,这可以一次完成,但是我要回退大约10个属性.

So yeah, that will work as a one off, but I'm pulling about 10 property attributes back.

作为一种解决方法,如果还有某种方式说只返回UserSmimeCertificate的前x位数字",我也将很高兴.

As a workaround option, I would also be happy if there was instead some way to say "just return the first x digits of the UserSmimeCertificate".

推荐答案

例如,您可以为此使用表达式属性.

You can use an expression property for this, for example.:

Get-ADUser -Filter * -Properties userSmimeCertificate | Select-Object Name, sid, @{Name="userSmimeCertificate"; Expression = {$_.userSmimeCertificate -is [System.Array]}}

这篇关于在PowerShell中对属性值返回true/false,而不是该值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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