Note: This tip requires PowerShell 3.0 or above.
Recently, on Windows Server 2012, I was trying to determine, both locally and remotely, if a user belongs to a specific group. For example, when I am running Hyper-V automation scripts, I need to determine if the currently logged-in user is part of Hyper-V administrators group or not.
In PowerShell 3.0, we can use CIM cmlets and associations to find this easily.
Get-CimInstance -Filter "Name='Jeff'" -ClassName Win32_UserAccount | Get-CimAssociatedInstance -Association Win32_GroupUser | Select-Object Name
Get-CimInstance -ClassName Win32_UserAccount -Filter "Name='$env:UserName'" -ComputerName Server-01 | Get-CimAssociatedInstance -Association Win32_GroupUser | Select-Object Name