Running PowerShell Script in different subnets

Welcome Forums General PowerShell Q&A Running PowerShell Script in different subnets

This topic contains 3 replies, has 3 voices, and was last updated by

1 year, 4 months ago.

  • Author
  • #81313

    Points: 18
    Rank: Member

    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 – )

    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")
  • #81326

    Points: 22
    Rank: Member

    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.

    • #81361

      Points: 18
      Rank: Member

      Thanks for your reply Leandro Wajswajn Pereyra...

      Here is the script that I posted in the link –

      $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
  • #81398

    Points: 0
    Rank: Member

    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

The topic ‘Running PowerShell Script in different subnets’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort