Skip to content

Instantly share code, notes, and snippets.

@nanusdad
Last active December 22, 2015 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanusdad/6393510 to your computer and use it in GitHub Desktop.
Save nanusdad/6393510 to your computer and use it in GitHub Desktop.
Using Powershell to run command line on remote machine

First, start powershell

      C:\Users\tester>powershell
      Windows PowerShell
      Copyright (C) 2009 Microsoft Corporation. All rights reserved.

Next, create remote sesssion

  PS C:\Users\tester> Enter-PSSession -ComputerName testserver

Then, set command variables

  [testserver]: PS C:\Users\tester\Documents> $tool="ipconfig.exe"
  [testserver]: PS C:\Users\tester\Documents> $cmdLine = "/all"

Finally, invoke the command

  [testserver]: PS C:\Users\tester\Documents> Invoke-Expression "$tool $cmdLine"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment