Setting Up PowerShell on Your Desktop to Support AD, Lync, and Exchange in the same Shell

You will find that there are many times you need to run PowerShell scripts or cmdlets from your desktop because you need a combination of modules or you have other needs.

For example, for many of the scripts that I run, I need the Quest Active Directory module that can be downloaded for free from here:

Set Execution Policy

You may need to set the script execution policy to run PowerShell scripts from your local console. Run, Set-ExecutionPolicy Unrestricted and that should work for you.

Configure a PowerShell Profile

You will want to configure a profile that will store your configuration on the computer.

  1. First, make sure you don’t already have a profile by running Test-Path $Profile

  2. Second, run New-Item –path $profile –type file –force to create a blank profile

  3. Then run Notepad $Profile to open up the profile and edit it.

Here is what I use in my $Profile:

Set-Location c:\scripts

Import-Module ActiveDirectory

Add-PsSnapin quest.activeroles.admanagement

# Import Exchange cmdlets

$e = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri

Import-PSSession $e

# Import Lync cmdlets

$l = New-PSSessionOption -SkipRevocationCheck -SkipCACheck –SkipCNCheck

$ls = New-PSSession -ConnectionUri -SessionOption $l -Authentication NegotiateWithImplicitCredential

Import-PSSession $ls

The first line sets the default starting location when PowerShell is started.

The second line is used to import the Active Directory cmdlets.

The third line adds the Quest cmdlets. Of course, this line is worthless unless you have installed the Quest tools, first.

The Exchange section follows. I would use these two lines, instead of the section used above for the lines for remoting, if I have the Exchange admin tools installed on the desktop:

Add-PSSanpin Microsoft.Exchange.Management.PowerShell.admin

Add-PSSanpin Microsoft.Exchange.Management.PowerShell.Support

The Lync section is after the Exchange section. I would also use this line if the Lync tools are installed on the computer:

Import-Module Lync

Run as AD Account

Running PowerShell as your standard user account is pretty much worthless. So, you can use the famous Run-As to start up PowerShell using your AD credentials.

Click Start, All Programs, Accessories, Windows PowerShell, then right-click the Windows PowerShell icon and select Properties.

In Properties, in the Target attribute, modify it like my example with everything on one line:

C:\Windows\System32\runas.exe /user:us\ad.russ ”%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe”

You might want to pin the icon to your Start Menu or create a short-cut. I find it so much easier that way.

This entry was posted in Exchange, Lync, PowerShell. Bookmark the permalink.

Leave a Reply

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

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s