Local User accounts
Delete local admin account
$StartTime = Get-Date #$MachineListFile = "h:\scripts\PowerShell\LocalUserAccounts\Machinelist.csv" $MachineListFile = "h:\scripts\PowerShell\LocalUserAccounts\Machinelist_test.csv" #initial export to create list #$XPMachines =Get-QADComputer -LdapFilter "(operatingSystem=*XP*)" | select name, Description, ParentContainer, operatingsystem, OSServicePack #$XPMachines = Import-Csv $MachineListFile $XPMachines = Get-QADComputer $env:computername | select name, Description, ParentContainer, operatingsystem, OSServicePack $UserToDelete = "testadmin" function ListUsers { foreach ($member in $Users.psbase.syncroot) {$member.name} } foreach ($Machine in $XPMachines) { $pingable=$(Test-Connection -Quiet -ComputerName $machine.name) $Machine | Add-Member -membertype noteproperty -name Pingable -Value $pingable #$Machine.Pingable = $pingable write-host $machine.name ", " $machine.operatingsystem "," $pingable if ($pingable) { Write-Host " looking for Admin User" $computer = [ADSI]("WinNT://" + $machine.name + ",computer") $Users = $computer.psbase.children | where{$_.psbase.schemaclassname -eq "User"} if ($(ListUsers) -contains $UserToDelete) { write-host " Found Admin User" $Machine | Add-Member -membertype noteproperty -name AccountExists -Value $true #$Machine.AccountExists = $true Write-Host " deleting local user $UserToDelete from $($Machine.name)" $Computer.Delete("user",$UserToDelete) } Else { write-host " No Admin User Found" $Machine | Add-Member -membertype noteproperty -name AccountExists -Value $false #$Machine.AccountExists = $false } } } Write-Host "exporting list to $MachineListFile" $XPMachines | Export-Csv $MachineListFile $StopTime = Get-Date $ElapsedTime =$StopTime - $StartTime Write-Host "this script ran for $([Math]::Round($ElapsedTime.TotalMinutes,0)) Minutes"