I am trying to capture the users in the local Administrators group from multiple servers on the network. I originally started with a script I found that does an WMI call, but all of those are blocked on the network.
I finally got the following to work, but When I get an error, it gives the Powershell error, and I would like to simplify it by just giving the short answer such as "Access is Denied" or "WinRM cannot process the request.", etc... I have to turn the report in to users who are non-technical.
I would like to capture the sentence following the following error message : to the period.
If there is a better way of doing this, or the output, I am open to suggestions.
Thanks for your help
$computerlist = get-content "C:\ServerList.txt"
ForEach ($computer in $computerList)
{
&{$computer
Invoke-Command -ComputerName $computer -ScriptBlock {Get-LocalGroupMember -Group administrators} |
Select-Object Name,PrincipalSource|Format-table -AutoSize
Write-Output " "} 2>&1 >>.\output.txt
}
[XXXXXXX] Connecting to remote server XXXXXXX failed with the following error message : WinRM cannot process the request. The following error occurred while using Kerberos authentication: Cannot find the computer XXXXXXX. Verify that the computer exists on the network and that the name provided is spelled correctly. For more information, see the about_Remote_Troubleshooting Help topic. + CategoryInfo : OpenError: (EPICSOAPT:String) [], PSRemotingTransportException + FullyQualifiedErrorId : NetworkPathNotFound,PSSessionStateBroken