Skip to content

Instantly share code, notes, and snippets.

@mikedopp
Created December 22, 2017 16:03
Show Gist options
  • Save mikedopp/b5c4bc0c4d4538343c32d8a72e280af0 to your computer and use it in GitHub Desktop.
Save mikedopp/b5c4bc0c4d4538343c32d8a72e280af0 to your computer and use it in GitHub Desktop.
Testing Somewhat Powershell Remoting.
Once you have enabled PowerShell remoting on a target machine, try and connect to it interactively. Here is a line you should try. Just make sure you replace “targetComputerName” with the name of the target computer you want to connect to:
PS C:\> Enter-PSSession -ComputerName targetComputerName
[targetComputerName]: PS C:\Users\User12\Documents> $env:COMPUTERNAME
TARGETCOMPUTERNAME
[targetComputerName]: PS C:\Users\User12\Documents> exit
PS C:\> $env:COMPUTERNAME
YOURCOMPUTERNAME
If connection fails with an “Access Denied”, you may want to use the –Credential parameter and log on to the remote computer using a different user account. You will need local Administrator privileges.
If your connection fails with an RDP error, or if WinRM cannot find the target computer name, check the connection with Test-WSMan, and if it cannot connect, review your remoting setup. You may have to run Enable-PSRemoting on the target machine first as described in an earlier tip.
Do not run commands that open windows. Only run commands that produce text information.
To leave the remote session, use “exit”.
NOT MY CODE. IT IS: http://community.idera.com/powershell/powertips/b/tips/posts/accessing-remote-machines-via-powershell-remoting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment