Connect to Microsoft Lync Server 2010 Remote PowerShell from the Desktop

By Nick Smith, Microsoft

Before running this script, ensure that the client meets all the requirements for a remote connection to Windows PowerShell. Here are the requirements:

· Windows PowerShell v2.0

· .NET Framework 2.0 Service Pack 1

· Windows Remote Management (WinRM) 2.0

The requirements are included in the Windows Management Framework, available for download. (For a detailed description of system requirements for Windows PowerShell 2.0, check out this support article: https://support.microsoft.com/kb/968929.)

To create a desktop shortcut to start a Windows PowerShell remote session connected to Microsoft Lync Server 2010, follow these instructions:

1. Open Notepad (or your favorite text or script editor).

2. Copy the following script and paste it into Notepad.

#*******************************************************************************

#* Author: Nick Smith (karsmith@microsoft.com)

#* Date: 6/20/2010

#* Purpose: This is a script that can be used when creating desktop icons that

#* will allow the user an easy way of connecting to remote powershell into a

#* Lync Server environment.

#* NOTE: THIS WAS DEVELOPED AGAINST LYNC SERVER BETA AND DOES NOT INCLUDE MUCH

#* ERROR CHECKING. USE AT YOUR OWN RISK.

#*******************************************************************************

Param (

    [switch] $AuthenticationPrompt = $false,

    [string] $CSPoolFQDN = (read-host "Enter the FQDN of the Lync Server Pool"),

    [string] $AdminUsername = "domain\username"

)

$Error.Clear()

If ($AuthenticationPrompt) {

    Write-Host -ForegroundColor Green "Requesting Credentials for Lync Server Administrative Session"

    $CSSession = New-PSSession -ConnectionUri https://$CSPoolFQDN/ocspowershell -Credential $AdminUsername -ErrorAction SilentlyContinue

}

else {

    $CSSession = New-PSSession -ConnectionUri https://$CSPoolFQDN/ocspowershell -Authentication NegotiateWithImplicitCredential -ErrorAction SilentlyContinue

}

If ($Error.count -gt 0){

    Write-Host -ForegroundColor Red "Unable to Connect to Lync Server Administrative Session`n Error:" $Error

}

else {

    $ImportResults = Import-PSSession -Session $CSSession

    Write-Host -ForegroundColor Green "Connected to Lync Server Administrative Session`nImported" $ImportResults.ExportedFunctions.count "CS Functions"

}

cd $env:UserProfile

3. Save the file with a .ps1 extension, for example, C:\Scripts\Start-CsRemotePowerShell.ps1

4. Create an shortcut on the client desktop with the following target. Be sure the change the highlighted values to match your environment.

o To use integrated authentication

§ powershell.exe -noexit -executionpolicy bypass -file c:\scripts\start- csremotepowershell.ps1 –CSPoolFQDN CSPool01.contoso.local

o To use an authentication prompt

§ powershell.exe -noexit -executionpolicy bypass -file c:\scripts\start- csremotepowershell.ps1 -AuthenticationPrompt -CSPoolFQDN CSpool01.contoso.local -AdminUsername contoso\administrator