viewing paste Unknown #21540 | PowerShell

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
# ==============================================================================================
# NAME: Listing Administrators and PowerUsers on remote machines  
#  
# AUTHOR: Mohamed Garrana ,  
# DATE  : 09/04/2010
#  
# COMMENT:  
# This script runs against an input file of computer names , connects to each computer and gets a list of the users in the  local Administrators  
#and powerusers Groups . the output can be a csv file which can be readable on excel with all the computers from the input file
# ==============================================================================================
function get-localusers {
        param(
        [Parameter(Mandatory=$true,valuefrompipeline=$true)]
        [string]$strComputer)
        begin {}
        Process {
                $adminlist =""
                $powerlist =""
                $computer = [ADSI]("WinNT://" + $strComputer + ",computer")
        if ($computer.psbase.name ) {
                  $AdminGroup = $computer.psbase.children.find("Administrators")
                  $powerGroup = $computer.psbase.children.find("Power Users")
                  $Adminmembers= $AdminGroup.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
                  $Powermembers= $PowerGroup.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
                  foreach ($admin in $Adminmembers) { $adminlist = $adminlist   $admin   "," }
                  foreach ($poweruser in $Powermembers) { $powerlist = $powerlist   $poweruser   "," }
                  $Computer = New-Object psobject
                  $computer | Add-Member noteproperty ComputerName $strComputer
                  $computer | Add-Member noteproperty Administrators $adminlist
                  $computer | Add-Member noteproperty PowerUsers $powerlist
                  Write-Output $computer
                                        }            
 
                }
end {}
}
 
Get-Content c:\adminscript\computers.txt | get-localusers | Export-Csv c:\adminscript\localusers.csv
Viewed 453 times, submitted by unknown.