PowerShell; Manage AD, Exchange, and Lync/SfB in one console

I’ve gotten to the point where I manage most things in my day job with PowerShell. It’s a lot faster to type Unlock-Account kjtrent; than it is to launch ADUC and find the account. I also don’t like having to open one tool for AD, one for Exchange, and another for Lync/SfB. Furthermore, I have separate credentials for signing on to my workstation and managing servers.

I’ve created a simple little PowerShell script that will prompt for credentials and use them to open remote sessions (no need to install anything) to the servers. Copy the code below and save it in a PS1 file. Enter the FQDN of your servers in between the quotes for the appropriate variables. Then make a new desktop shortcut with the following path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit “C:\Users\profile\Documents\AdminShell.ps1” and pin the shortcut to your start menu. When you double-click it you’ll be prompted for credentials and a PowerShell window will open with the remote sessions loaded. It will stay open until you close it.

#Enter the FQDN for your servers below between the "
$exchfqdn = "your exchange server fqdn"
$sfbfqdn = "your Skype for Business / Lync FE Server FQDN"
$adfqdn = "your DomainController FQDN"

$ErrorActionPreference = 'SilentlyContinue'
$WarningPreference = 'SilentlyContinue'
$UserCredential = Get-Credential -Message "Credentials are required to access AD, Exchange, and SfB; use the detected username or enter a differerent account" -UserName ($env:userdomain +'\'+ $env:USERNAME)
$ExSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$exchfqdn/PowerShell/ -Authentication Kerberos -Credential $UserCredential
$SfBSession = New-PSSession -ConnectionUri https://$sfbfqdn/OCSPowerShell -Credential $UserCredential
$ADSession = New-PSSession -ComputerName $adfqdn -Credential $UserCredential
Import-PSSession $ExSession
Import-PSSession $SfBSession
Import-PSSession $ADSession

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s