Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
609 views
in Technique[技术] by (71.8m points)

boolean - Return true/false on property value in PowerShell, not the value

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

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.

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]

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

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".

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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]}}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...