Powershell For Lync Server 2010 Getting Started: Remoting
Powershell For Lync Server 2010 Getting Started: Remoting
Microsoft Lync Server 2010 ships with over 500 Lync-specific PowerShell cmdlets which provide complete management over a Lync deployment. This cheat sheet will help you get started, accomplish frequent management tasks, and provide tips for particular 'gotchas'.
Getting Started
The PowerShell cmdlets for Lync Server are accessible through the Lync Server Management Shell. It is installed with "Install Topology Builder" step in the Lync Server Deployment Wizard. To start it locally: Start Menu | All Programs | Microsoft Lync Server 2010 | Lync Server Management Shell.
Remoting
Most Lync Server PowerShell cmdlets leverage the remote management capabilities of Microsoft PowerShell Version 2.0 to read or write from Lync system objects stored in either the Lync Central Management Store (CMS) or AD. As such, they can be run remotely on any computer where the Lync Server Management is installed. You can also manage Lync Server from a computer where the Lync Management Shell has not been installed using a Remote PowerShell session. See http://blogs.technet.com/b/csps/ archive/2010/06/16/qsremoteaccess.aspx for more information.
Permissions
Lync Server 2010 uses role-based access control (RBAC) to grant or deny administrative privileges. Each Lync cmdlet requires the AD user running the cmdlet to have at least one of the RBAC role(s) assigned to that cmdlet. There are 11 pre-define Lync Server RBAC roles. For more details see http://technet.microsoft.com/en-us/library/gg425917.aspx. To see a list of RBAC roles assigned to a user:
A small number of Lync cmdlets are specific to a Lync server and the "-ComputerName" parameter is needed to identify the server. For example, to return detailed information about the Lync Server 2010 components that runs as Windows services on "Server01" use:
Get-CsAdminRoleAssignment SamAccountName
(Note: you must use the SamAccountName when specifying the user Identity for this cmdlet). To see a list of RBAC roles can run the cmdlet "Cs-CsAdUser":
Add the user AD account to the AD security group associated with the Lync RBAC role.
Note: RBAC restrictions in the Lync Server Management Shell only apply remotely. A user running cmdlets in the local Lync Management shell session (e.g. on the server) are not subject to RBAC restrictions.
Both cmdlets return information about Lync users. Use Get-CsUser unless you require access to the generic AD attributes, or if the user has not been enabled for Lync Server.
Show all the properties returned by Get-CsUser:
Get-CsUser | Get-Member
Show the number of Lync enabled users:
@(Get-CsUser).Count
Get all AD users who are not, and who have never been, enabled for Lync or OCS:
Getting Help
Get basic help for a cmdlet:
Get-CsUser -UnassignedUser
Get all Lync Users in the Sales Department:
Lync_ITPro.CHM
(http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9720c3f1-ddd4-426b-b98a-f1205561ce00)
Get-CsUser Bob*
Get all the SIP addresses in your Lync deployment:
Get-CsUser | Get-Member
New-CsExternalAccessPolicy -Identity PublicIMEnabled ` -EnablePublicCloudAccess $True Get-CsUser -LdapFilter "Department=Support" | Grant-CsExternalAccessPolicy -Policy PublicIMEnabled
Enable all external access features for all users in Lync "Site01", including video with Public IM contacts:
(Get-CsUser [email protected]).VoicePolicy
Get all Lync users with the 'Long Distance' Voice Policy:
New-CsExternalAccessPolicy -Identity site:Site01 -EnableFederationAccess ` $True -EnableOutsideAccess $True -EnablePublicCloudAccess $True ` -EnablePublicCloudAudioVideoAccess $True
(Note: because the new Site01 policy above is created at the Lync Site scope, it sets the external access properties for all Lync users in that site after creating the policy. No follow-on Grant-CsExternalAccessPolicy is required). Remove an External Access Policy from "User01":
Get-CsUserPoolInfo [email protected]
Get a list of users homed on OCS 2007 R2 or OCS 2007:
Get-CsUser -OnOfficeCommunicationServer
Get a list of all the user policies assigned to Lync "User01":
Managing Users
Enable AD user "User01" for Lync:
Disable-CsUser [email protected]
(Note: this will keep the AD account, but it will be disabled for Lync. Lync attributes, including SIP address, will need to be reset if the account is re-enabled for Lync). How are Lync users enabled & disabled for Federation, Public IM, and Internet (i.e. Remote) Access?
Managing these features is done by applying a Lync External User Access Policy. This policy can be set at a Global, Site, or User scope.
Modify the default Global External User Access Policy to enable Federation and Internet Access:
Get-CsClientPolicy
Page 2
function Get-LyncSiteUser { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [System.String] $LyncSiteName) $pools = @(Get-CsSite $LyncSiteName | Select-Object -ExpandProperty Pools) if ($pools.Count -gt 0) { Get-CsUser | Where-Object {$pools -contains $_.RegistrarPool} | Sort-Object RegistrarPool } } Get-LyncSiteUser Site01 | Format-Table DisplayName -GroupBy RegistrarPool
Change the maximum number of contacts allowed for Lync "User01" to 500 in an existing users client policy (if one exists):
Change how often Address Book servers synchronizes with the data stored in the User database to 2 min:
$cred = Get-Credential "domain\User01" Test-CsAddressBookService -TargetFqdn Pool01.example.com ` -UserCredential $cred -UserSipAddress "sip:[email protected]"
Show the User Replicator configuration settings in a Lync organization:
Get-CsUserReplicatorConfiguration
Get-CsTopology
(Note: use the follow-on | Select-Object -ExpandProperty <property name> to expand and show the multi-valued properties such as Services). Verify that a Lync deployment is functioning correctly at a global level:
Test-CsTopology
Show the Simple Url's in a Lync organization:
Get-CsDeviceUpdateConfiguration
Show the Lync 2010 Phone Edition configuration settings:
Get-CsUCPhoneConfiguration
Show all analog devices managed by Lync Server:
Get-CsManagementStoreReplicationStatus
Get-CsAnalogDevice
Test if the user with phone number "+1 123 123 1234" can logon using a Lync 2010 Phone Edition-compatible device:
Sites
Show all Central Lync sites and information about them:
The Lync Address book is a set of files holding AD user information that is used by Lync clients to search for contacts and normalize dialed numbers. User information from AD is synchronized into a Lync User Database by the Lync User Replicator. The Lync Address Book files are then generated from the data in the User Database, and synchronized every 5 minutes (by default). Manually force the Address Book files on all Address Book servers to update from the Lync User Database:
Update-CsAddressBook
Get the Address Book configuration settings:
Get-CsAddressBookConfiguration
Version 1.0 January 21, 2011 - Find the latest version of this cheat sheet and provide feedback at: http://www.insidelync.com/PSCheatSheet
Pools
Show all Lync Pools and information about them:
Get-CsPool
Show all computers used in each Lync pool:
$cred = Get-Credential "domain\User01" Test-CsRegistration -TargetFqdn Pool01.example.com ` -UserCredential $cred -UserSipAddress sip:User01.example.com
For more information on how to get all active connections on a registrar pool: http://blogs.technet.com/b/csps/archive/2010/06/10/list-connections-to-registrar-pools.aspx Page 3
Server Roles
Show all Lync server roles, their configuration, and associated Lync service(s):
Get-CsService
Show all Lync servers of a particular role, and their configuration:
Computers
Show information about all the computers used in a Lync Server deployment:
Get-CsNetworkInterface
Get the configuration settings for computers running the Access Edge service (e.g. AllowFederatedUsers):
Get-CsAccessEdgeConfiguration
Report on the status of the Lync services running locally:
Version 1.0 January 21, 2011 - Find the latest version of this cheat sheet and provide feedback at: http://www.insidelync.com/PSCheatSheet
Page 4
Test a dialed number against the Global Dial Plan. The matching normalization rule will be displayed along with the translated number:
Gotchas
There are a few Lync PowerShell 'gotchas' to keep in mind:
(Get-CsPstnUsage).Usage
Show all any Voice Routes that do not have a PSTN Gateway associated with it:
$cred = Get-Credential "domain\User01" Test-CsPstnOutboundCall -TargetFqdn Pool01.example.com ` -TargetPstnPhoneNumber "+14251231234" -UserSipAddress ` "sip:[email protected]" -UserCredential $cred
Show the current inbound and outbound calls on Lync Mediation server "MedServer01":
The User scope is controlled through the Set-CsClientPolicy, New-CsClientPolicy, and Grant-CsClientPolicy cmdlets. The User policy setting takes precedence as long as the maximum number configured in it is less than the maximum set in the Global, Site, or Service levels.
Useful Links
Microsoft TechNet: Lync 2010 Management Shell Lync 2010 Cmdlets by Category
Lync 2010 PowerShell Blog Free PowerShell community, forums, administrative and scripting/debugging tools: http://PowerGUI.org Lync Tips, Tricks, & Insight: http://www.InsideLync.com
Author
Curtis Johnstone http://www.InsideLync.com & http://www.InsideOCS.com
Contributors
Kirk Munro http://poshoholic.com
Version 1.0 January 21, 2011 - Find the latest version of this cheat sheet and provide feedback at: http://www.insidelync.com/PSCheatSheet
Page 5