Combreal

Get-LocalAdmin.psm1

Sep 25th, 2020
1,065
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .SYNOPSIS
  3. This script list the member of the Administors group for a machine passed in parameter
  4. #>
  5.  
  6. function Get-LocalAdmin
  7. {  
  8.     param ($strcomputer)  
  9.      
  10.     $admins = Gwmi win32_groupuser –computer $strcomputer  
  11.     $admins2 = $admins |? {$_.groupcomponent –like '*"Administrators"'}  
  12.     if($admins2 -eq $null)
  13.     {
  14.         $admins2 = $admins |? {$_.groupcomponent –like '*"Administrators"'}
  15.     }
  16.     $admins |% {$_.partcomponent –match “.+Domain\=(.+)\,Name\=(.+)$” > $nul
  17.     $matches[1].trim('"') + “\” + $matches[2].trim('"')}  
  18. }
  19.  
  20. Export-ModuleMember -Function Get-LocalAdmin
RAW Paste Data