Created
October 1, 2016 18:12
-
-
Save FuzzySecurity/5f501ccc5e3a2b5641a50ccf05286a9a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-LocalGroup { | |
# PS C:\Users\IEUser\Desktop> Get-LocalGroup -GroupName Administrators | |
# | |
# AccountName AccountSID | |
# ----------- ---------- | |
# Administrator S-1-5-21-1116692041-1164204812-2329106322-500 | |
# IEUser S-1-5-21-1116692041-1164204812-2329106322-1000 | |
# sshd_server S-1-5-21-1116692041-1164204812-2329106322-1002 | |
param( | |
[String]$GroupName | |
) | |
# Result array | |
$UserArray = @() | |
# Fubar WMI Query | |
(Get-WMIObject win32_group -filter "LocalAccount='True'" -ComputerName $env:COMPUTERNAME | Where-Object { | |
$_.Name -eq $GroupName | |
} | select @{ | |
Name="Members";Expression={$_.GetRelated("win32_useraccount").Name} | |
}).Members | foreach { | |
$HashTable = @{ | |
AccountName = $_ | |
AccountSID = (New-Object System.Security.Principal.NTAccount($_)).Translate([System.Security.Principal.SecurityIdentifier]).Value | |
} | |
$Object = New-Object PSObject -Property $HashTable | |
$UserArray += $Object | |
} | |
# Print array | |
$UserArray |Format-Table -AutoSize | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment