Skip to content

Instantly share code, notes, and snippets.

@mbrownnycnyc
Created July 29, 2015 16:16
Show Gist options
  • Save mbrownnycnyc/55720cc4d1c999c0c7d4 to your computer and use it in GitHub Desktop.
Save mbrownnycnyc/55720cc4d1c999c0c7d4 to your computer and use it in GitHub Desktop.
Very quick/raw script to get a list of members of local admin group in a resultant !! separated list
#--- Lists local users in local Administrators group: ---
((get-wmiobject Win32_GroupUser -computer $computername | `
where { `
( $_.GroupComponent -like '*Administrators*' ) `
-and
( $_.GroupComponent -notlike '*$((get-wmiobject win32_computersystem).domain.split('.')[0])*' ) `
-and `
( $_.PartComponent -like '*Win32_UserAccount*') `
-and `
(
( $_.PartComponent -like "*Domain=""$computername""*") `
-or `
( $_.PartComponent -notlike "*Domain=""$((get-wmiobject win32_computersystem).domain.split('.')[0])""*") `
) `
} `
).partcomponent) | foreach { ($_).split('"')[1,3] ; "!!"}
#--- Lists local and domain users in local Administrators group: ---
((get-wmiobject Win32_GroupUser -computer $computername | `
where { `
( $_.GroupComponent -like '*Administrators*' ) `
-and
( $_.GroupComponent -notlike '*$((get-wmiobject win32_computersystem).domain.split('.')[0])*' ) `
-and `
( $_.PartComponent -like '*Win32_UserAccount*') `
-and `
(
( $_.PartComponent -like "*Domain=""$computername""*") `
-or `
( $_.PartComponent -like "*Domain=""$((get-wmiobject win32_computersystem).domain.split('.')[0])""*") `
) `
} `
).partcomponent) | foreach { ($_).split('"')[1,3] ; "!!"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment