Establish remote PowerShell session

Imagine, you are working on perfectly good workstations, enjoying your GUI and you get a task to perform some maintenance on Windows Server, that has the “User interfaces and infrastructure” feature removed.

One way is to utilize PowerShell, the task automation, and configuration management framework developed by Microsoft about 10 years ago.

So to initialize remote PowerShell session, it takes:

  1. On the targeted server/ computer type:
    1. Enable-PSRemoting -Force //will change the needed configuration settings
    2. Or you can set a GPO, as shown here.
  2. On your machine enter:
    1. $cred = Get-Credential // get your domain credentials
    2. $rhost=”olp-dc2″ // setting the value for remote host
    3. Enter-PSSession -ComputerName _._.com -Credential $cred // fill out the computer name and the name of the user you want to use
    4. hostname // to check if you are running PowerShell in the host
    5. Get-PSSession //
    6. Enter-PSSessionComputerName _._.com -Credentials $cred // to switch to another PowerShell session
    7. Exit-PSSession // will kill the PowerShell session, as well as typing just exit
    8. Get-PSsession $computer-name // will show you the ongoing sesions
    9. Or just type exit to leave the session.

And as visable, powershell wont let you forget which session you are working in right now :).

You can see the on which the session is running in the begining of each row,
The result of Get-PSSession for the server in use.
overview of remote PowerShell

Aditional examples, can be found here and here.