I want to get all user account messages in Windows operating system from remote Linux machine. There are no any services or functions that can support it in Windows operating system. Now I connect to Windows operating system using WinRM. I remotely execute cmd commands, such as "net user". Are there better methods that can replace present solution?
Asked
Active
Viewed 82 times
1 Answers
0
I often use the "List Local Users from Remote Computers" PowerShell script from Prakash Kumar. The script uses WMI to get the users list and exports them nicely formated.
get-content "Servers.txt" | foreach-object {
$Comp = $_
if (test-connection -computername $Comp -count 1 -quiet)
{
([ADSI]"WinNT://$comp").Children | ?{$_.SchemaClassName -eq 'user'} | %{
$groups = $_.Groups() | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
$_ | Select @{n='Server';e={$comp}},
@{n='UserName';e={$_.Name}},
@{n='Active';e={if($_.PasswordAge -like 0){$false} else{$true}}},
@{n='PasswordExpired';e={if($_.PasswordExpired){$true} else{$false}}},
@{n='PasswordAgeDays';e={[math]::Round($_.PasswordAge[0]/86400,0)}},
@{n='LastLogin';e={$_.LastLogin}},
@{n='Groups';e={$groups -join ';'}},
@{n='Description';e={$_.Description}}
}
} Else {Write-Warning "Server '$Comp' is Unreachable hence Could not fetch data"}
}|Export-Csv -NoTypeInformation LocalUsers.csv

bjoster
- 4,805
- 5
- 25
- 33
-
The remote machine in my question may be Linux operating system. The script above only run on the Windows PowerShell environment. I think that the answer is a python program that can run on Linux or Windows operating system. – ming li Feb 14 '20 at 03:29
-
This information ("source machine is linux") would have been helpful *in* the question. – bjoster Feb 14 '20 at 09:06