MilesLogan
asked on
Powershell - How to pull all Local Accounts from multiple machines
Hi EE
I have the script below that Subsun helped me with . It was originally set to pull the member of the Administrators group but I was trying to modify it to pull all Local Accounts and its pulling members of the local Users group only not all Local Accounts .
Any ideas ? I dont have to use this scrtipt if someone already has something different.
function get-localusers {
param(
[Parameter(Mandatory=$true ,valuefrom pipeline=$ true)]
[string]$strComputer)
begin {}
Process {
$Select = "Name","Class" | %{
Invoke-Expression "@{n='$_';e={ `$_.GetType().InvokeMember ('$_', 'GetProperty', `$Null, `$_, `$Null) }}"
}
If (Test-Connection $strComputer -Count 2 -Quiet){
$Users =""
$computer = [ADSI]("WinNT://" + $strComputer + ",computer")
$UsersGroup = $computer.psbase.children. find("User s")
$Usermembers= $UsersGroup.psbase.invoke( "Members") | Select $Select
foreach ($Users in $Usermembers) {
$Users | Select @{N="ComputerName";E={$str Computer}} ,@{N="User s";E={$_.N ame}},Clas s
}
}
Else {
"" | Select @{N="ComputerName";E={$str Computer}} ,@{N="User s";E={"Not able to Ping"}},Class
}
}
end {}
}
Get-Content "e:\Projects\servers\Serve rs.txt" | get-localusers | Select ComputerName,Users,Class | Export-Csv "e:\Projects\Servers\Local Test_$((ge t-date).to String('MM -dd-yyyy') ).csv" -NTI
I have the script below that Subsun helped me with . It was originally set to pull the member of the Administrators group but I was trying to modify it to pull all Local Accounts and its pulling members of the local Users group only not all Local Accounts .
Any ideas ? I dont have to use this scrtipt if someone already has something different.
function get-localusers {
param(
[Parameter(Mandatory=$true
[string]$strComputer)
begin {}
Process {
$Select = "Name","Class" | %{
Invoke-Expression "@{n='$_';e={ `$_.GetType().InvokeMember
}
If (Test-Connection $strComputer -Count 2 -Quiet){
$Users =""
$computer = [ADSI]("WinNT://" + $strComputer + ",computer")
$UsersGroup = $computer.psbase.children.
$Usermembers= $UsersGroup.psbase.invoke(
foreach ($Users in $Usermembers) {
$Users | Select @{N="ComputerName";E={$str
}
}
Else {
"" | Select @{N="ComputerName";E={$str
}
}
end {}
}
Get-Content "e:\Projects\servers\Serve
ASKER
Hi Subsun , I don't get an error but it just loops and it does not output any data .
I just tested the code and I am getting the following result..
Are you getting the user details when you run the following command?
"ComputerName","User"
"ServerA","Not able to Ping"
"ServerB","Not able to Ping"
"TestSRV","Administrator"
"TestSRV","Guest"
"TestSRV","TestUser"
Are you getting the user details when you run the following command?
Get-WmiObject Win32_UserAccount -ComputerName ServerA
ASKER
Below will pull Local Users from an XP machine but if I want the local users from Server 2003/2008 it does not .. same with the full script
Get-WmiObject Win32_UserAccount -ComputerName ServerA
Get-WmiObject Win32_UserAccount -ComputerName ServerA
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
WOW Subsun ! you always help out so much ! thanks !
I am opening a new question to modify this same script if it can show if the user is Disabled/Enabled and possibly the Full Name and Description .
I am opening a new question to modify this same script if it can show if the user is Disabled/Enabled and possibly the Full Name and Description .
Open in new window