Using PSEXEC remotely via PS

Welcome Forums General PowerShell Q&A Using PSEXEC remotely via PS

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

3 years, 8 months ago.

  • Author
  • #24252

    Points: 1
    Rank: Member


    Just getting to grips with the syntax of PS and have been tasked with :

      Listing all members of Remote Desktop Users for clients servers
      Listing all local accounts for clients servers

    Regarding the incantations to get the relevant info, I know this works from a PS prompt:

    psexec.exe \\SERVERNAME "net" localgroup "Remote Desktop Users"

    (Yay Russinovich, right?)

    And I know this ALMOST works from a PS prompt:

    psexec.exe \\SERVERNAME "net" users

    (It bombs out right at the end of showing the local user list with error code 1)

    So, I think in PS, from peeping other snippets out there, the following will ALMOST do it:

    $computers = Get-Content 'c:\temp\serverlist.txt'
    Foreach $computer in $computers {
        psexec.exe \\$computer "net" localgroup "Remote Desktop Users"

    It's \\$computer syntax I can't seem to get right. I also just need to make the loop spit out the computer name and get the remote "net users" to do the business.

    Any ideas? I am nearly there, right?

  • #24253

    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    Double quotes? "\\$computer"

    Me, I'd query this with WMI, or via PSRemoting, but that's me. PSExec is kinda old-school for me. But if it's what's in place, and nothing else is an option, sure.

  • #24260

    Points: 1
    Rank: Member


    I've tried the WMI side this morning but I'd have to visit most of the servers to sort firewall rules on. There are 94 in the list and they want it done ASAP. Some are 2012, some 2008, some 2003, some are wooden beads.

    I think I'm going to be doing something 94 times, aren't I? 🙁

  • #24261

    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    Maybe. Sorting your firewall is going to be of key importance, whether you're enabling WMI (not very forward-looking, but all you can do on 2003/2008) or allowing WS-MAN traffic (more forward-compatible). If they're domain-joined, it can be done with a GPO. The firewall can even be modified via PsExec, if that's in place. But at some point, you're going to hit a wall with PsExec, and you'll want to be able to use the better technologies that have been invented in, oh, the last eight years ;).

    I mean, hell, ADSI with the WinNT:// provider could do this, and that dates back to 2000. But it isn't "the way forward."

    I'd argue that getting this done the right way will enable a lot more ASAP in the future. "Investment." "ROI." Those are words I'd use.

The topic ‘Using PSEXEC remotely via PS’ is closed to new replies.