PowerShell for Windows Admins

Jun 25 2013   12:46PM GMT

The inverse association



Posted by: Richard Siddaway
Tags:
PowerShell
PowerShell 3
WMI

In my last post I showed how to find the groups of which a local user is a member. A comment was left asking about the inverse relationship.

In this case we can just turn the code round.

Get-CimInstance -ClassName Win32_Group |
foreach {
$users = Get-CimAssociatedInstance -InputObject $psitem `
-ResultClassName Win32_UserAccount |
select -ExpandProperty Caption

$psitem | Add-Member -MemberType NoteProperty -Name ‘Users’ `
-Value ($users -join “;”) -PassThru

} | select Name, Users

Note: You can’t do this as a matter of course with all WMI relationships. Some relationships are one way in that A has a link to B but B has no way to link back to A unless you can find a property in common.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: