Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [CmdletBinding()]
- param
- (
- [Parameter(Mandatory=$false, Position = 0)]
- [string[]] $GroupsToExclude
- )
- Begin
- {
- $groupNames = Get-CimInstance -ClassName Win32_Group -Filter "Domain='$env:COMPUTERNAME'" -Property Name | Select-Object -ExpandProperty Name
- [string[]] $groupNames = $groupNames | Where-Object { $_ -notin $GroupsToExclude }
- $de = [adsi]"WinNT://$env:COMPUTERNAME"
- }
- Process
- {
- foreach ($groupName in $groupNames)
- {
- try
- {
- $adminGroup = $de.Children.Find($groupName, "Group")
- foreach ($mem in $adminGroup.psbase.Invoke("members"))
- {
- $type = $mem.GetType()
- $name = $type.InvokeMember("Name", "GetProperty", $null, $mem, $null)
- [byte[]] $sidBytes = $type.InvokeMember("ObjectSid", "GetProperty", $null, $mem, $null)
- $sid = New-Object System.Security.Principal.SecurityIdentifier($sidBytes, 0)
- [pscustomobject]@{
- Group = $groupName
- Name = $name
- Sid = $sid.Value
- }
- }
- }
- finally
- {
- $adminGroup.Dispose()
- }
- }
- }
- End
- {
- $de.Dispose()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement