Saturday, December 29, 2018

Exchange 2016 - Create Remote PowerShell Shortcut

A growing trend for organizations is to lock down direct remote access to servers, requiring the need for Remote PowerShell Sessions to manage things like Exchange. The problem is, it's a nuisance to create a remote session every time you need to connect to Exchange.

To save time (and my sanity) I decided to create a shortcut that will start the remote session automatically when you run it.

Copy the following information into Notepad:

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://mail.exchangeitup.com/PowerShell/ -Authentication Kerberos -Credential $UserCredential
Import-PSSession $Session -DisableNameChecking

**Note** Change -ConnectionURI to match your Exchange namespace or a server name (if you don't publish PowerShell).

Save it as a .ps1 with a name like Exchange-RemotePS.ps1 to somewhere like C:\Scripts

Next, create a PowerShell shortcut anywhere, like on your Desktop:

Right-click the Desktop > New > Shortcut

New Shortcut
In the location field, enter:
PowerShell Shortcut
Click Next
Give it a name like ExchangeRemotePS and click Finish.
ExchangeRemotePS Shortcut

Right-click the new ExchangeRemotePS shortcut, and go to Properties.
In the Target field, add the following to the end of the line:
-NoExit -File "C:\Scripts\Exchange-RemotePS.ps1"
It will look like so:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit -File "C:\Scripts\Exchange-RemotePS.ps1"
Shortcut Target
Click OK.
Run your new shortcut, and you'll get a creds prompt for your Exchange organization.
Once it starts the remote session, you'll be able to run your Exchange cmdlets.
Remote PowerShell Session
Now, you can use that new shortcut instead of tiring out your fingers before even getting into Exchange!

No comments:

Post a Comment