Running PowerShell Script in different subnets

Hi All…I would like to get your advice on running powershell script in different subnets. When I ran scripts against multiple servers, got error as mentioned below (which I have shared in the link - https://powershell.org/forums/topic/script-to-get-user-ids-on-remote-servers/ )

Pls share expertise & let me know if there are any ways to work around…much appreciated.

  
Exception calling "Invoke" with "2" argument(s): "The network path was not found
At C:\Temp\Users-GroupMember\Users-GroupMember.ps1:17 char:32

+ FullyQualifiedErrorId : DotNetMethodException
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ $members = $Group.psbase.Invoke < <<< ("Members")

Subnets shouldn’t be an issue. Can you post a little bit more of your script?

Given the error line, it seems you are using WinNT connection (or ADSI). You might wanna check your name resolution as well.

Thanks for your reply Leandro Wajswajn Pereyra…

Here is the script that I posted in the link - https://powershell.org/forums/topic/script-to-get-user-ids-on-remote-servers

$Output = "C:\Temp\Users-GroupMember\UserInfo.rtf"
$Servers = Get-Content -Path "C:\Temp\Users-GroupMember\Servers.txt"

foreach ($Servers in $Servers)

{
# 1. To get Local Administrators group Members

Write-Output "1. *****Administrators group Members for the Server mentioned above****" |out-file $Output -Append

$localgroup = "Administrators"
$Group= [ADSI]"WinNT://$Servers/$LocalGroup,group" 
$members = $Group.psbase.Invoke("Members")
$members | ForEach-Object { $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null) } | Out-File $Output -Append

# 2. Local user information

Write-Output "2. *****Local user information for the Server mentioned above*****" | out-file $Output -Append

$adsi = [ADSI]"WinNT://$Servers"
$adsi.Children | where {$_.SchemaClassName -eq 'user'} | Foreach-Object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)} | out-file $Output -Append
} 

I don’t see how this line will work
$Group= [ADSI]“WinNT://$Servers/$LocalGroup,group”

$servers contains multiple computers but the syntax should be

$Group= [ADSI]“WinNT:///$LocalGroup,group”

You’ll need to change your code to loop through the computers in $servers