13 November 2014

Remote Powershell sessions for AD & Exchange on Windows 7, 8 & 10

Working from a Windows 7, 8 or 10 machine without the RSAT tools?
Create a shortcut to the Active Directory and Exchange PowerShell tools.

Copy and paste in to a new text file and save as: "D:\RemoteDCSession.ps1"

$RemoteDC = "sr-XXXXX.Company.lan"
$s = new-pssession -computer $RemoteDC
Invoke-Command -session $s -script { Import-Module ActiveDirectory }
Import-PSSession -session $s -module ActiveDirectory
Create a new shortcut to Powershell and name it "RemoteDCSession".
Edit the shortcut at the Target and enter: 


C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command ". 'd:\remotedcsession.ps1'"


When the Shortcut has been edited, shift right click it and select "Run as a different user".
Enter your credentials and the PowerShell console will load the Active Directory command-lets.

The same goes for the Exchange PowerShell command-lets.

Copy and paste in to a new text file and save as: "D:\RemoteEXSession.ps1"

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://sr-XXXXX.Company.lan/powershell" -Authentication Kerberos or Negotiate
import-pssession $session

Create a new shortcut to Powershell and name it "RemoteEXSession".
Edit the shortcut at the Target and enter:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command ". 'd:\remoteexsession.ps1'"



When the Shortcut has been edited shift right click it and select "Run as a different user".
Enter your credentials and the PowerShell console will load the Exchange command-lets.

Don't forget to exit the session, otherwise all the Powershell session will be used and there will be none left when you try to start aother session.


Get-Psssession | fl id,session


Remove-Psssession - id <id-number>

Or


Remove-psssession -name <Sessionname>

No comments:

Post a Comment