PS One Liners

Since I can never remember the script I thought it best to publish the ones I use often here.
For quick reference to Lync Powershell Commandlet Index click here

Get Server Version and CU Update level
Get-WmiObject –query ‘select * from win32_product’ | where {$ –like “Microsoft Lync Server*”} | ft Name, Version –AutoSize

Export all OCS users to csv
Get-CsUser -onofficecommunicationserver | Format-Table -Property DisplayName, sipaddress | Export-Csv –Path C:OCSUsers.csv
Export all Lync users to csv (examples)
Get-CsUser | select-object DisplayName,LineUri,EnterpriseVoiceEnabled | export-csv c:users.csv
Get-CsUser | Format-Table DisplayName, Enabled, SipAddress | Export-Csv –Path C:Users.csv
The above command excludes Common Area Phones

Enable all users in an OU for Lync
get-csADuser -OU “OU=Users,OU=Auckland,dc=lynclab,dc=co,dc=nz” | Enable-CsUser -RegistrarPool -SipAddressType emailaddress
Enable all users in an OU for Lync (exporting these to csv)
Get-CsADuser | Format-Table DisplayName | Export-Csv –Path C:ADUsers.csv
get-csADuser -OU “OU=Users,OU=Auckland,dc=lynclab,dc=co,dc=nz” | Enable-CsUser -RegistrarPool -SipAddressType emailaddress
Take all the users still homed on OCS and migrates all to Lync Server:
Get-CsUser –OnOfficeCommunicationServer | Move-CsLegacyUser –Target “<pool FQDN>”
Get-CsUser -OnOfficeCommunicationServer | export-csv c:tempOCS.csv
Normalization to ITSP – Removing Extension numbers
New-CsOutBoundCallingNumberTranslationRule -Parent Global -Pattern “^(+d+)(s*S)*$” -Translation ‘$1’ -Name “Remove Extensions”
Creating a config file to feed Edge server (not on the Domain)
Export-CsConfiguration -FileName “”
Unassigned Numbers routed to IVR (No announcement in this case)
New-CsAnnouncement -Parent service:ApplicationServer:<Lync FE FQDN> -Name “Unassigned numbers to IVR” -TargetUri “;user=phone“Added the range in Lync Manager – Voice Features – Unassigned Numbers – Range +6499502500 – +64999502599 (covers all unassigned numbers from 500 – 599)

Unassigned Numbers (Text Announcement)
New-CsAnnouncement -Parent service:ApplicationServer:<Lync FE FQDN> -Name “Unassigned Numbers” -TextToSpeechPrompt “The Number you have dialed is not currently in use, please hold to be transferred to an operator.” -Language “en-US” -TargetUri
Assigning a Private Telephone Line
Set-CsUser -Identity “” -PrivateLine “Tel:+6499502534”.
Removing Private Lines
Set-CsUser <Identity of user> -PrivateLine $NULL
Show All Users that have Private Lines
Get-CsUser | Where {$_.privateline -ne “”} | FL Identity, PrivateLine

Move All users in an OU to a common Voice Policy

Get-CsUser -OU “ou=users,dc=lynclab,dc=co,dc=nz” | Grant-CsVoicePolicy -PolicyName “SIP Voice Policy”


Get numbers stored in AD

get-aduser -<Identity of user> -properties *|Format-List name, mobile,telephoneNumber.msRTCSIP-Line


Enabling MoH Globally

Set-CSClientPolicy Global -EnableClientMusicOnHold:$TRUE
MoH Policy to force company wide MoH
Set-CSClientPolicy -EnableClientMusicOnHold:$TRUE -MusicOnHoldAudioFile pathtoaudiofile.wma
(keep in mind that this needs to be a path the clients can access to collect the music file)
Stop notification of being added as a contact
set-CSClientPolicy – EnableNotificationForNewSubscribers $False
Changing the DG refresh interval from 8 days (default) to 5 minutes
set-CSClientPolicy global -DGrefreshinterval:00:05:00
Make Lync Call Default
After implementation of Enterprise Voice in Lync 2010, we noticed that the Work number became the default calling method from Lync.
We wanted to change this behavior, and make Lync Call the default and preferred calling method.
To solve this, the following PowerShell command was issued:
Set-CsClientPolicy -EnableVOIPCallDefault $True
Disable Save activity in Outlook Conversation History
Set-CsClientPolicy –EnableIMAutoArchiving $false –EnableCallLogAutoArchiving $false
(Can always create a seperate policy using the – Identity <no conv history policy name>
Extending the Distribution Group Expansion size limit
Set-CsWebServiceConfiguration – Shows current limit (default 100)
Set-CsWebServiceConfiguration -maxgroupsizetoexpand 200 – I have been told that its limited to 150 ??
GAL Download or Web Query
Set-CsClientPolicy -AddressBookAvailability websearchonly

Prevent Lync from synchronizing with Outlook contact

set-csclientPolicy -identity:global -ExcludedContactFolders “Contacts;Suggested Contacts”
Forcing an Update from the Server
Update-CsAddressBook -verbose (ABServer -SyncNow) wait 5 minutesFinding Contact Merge issues

Graceful Shut Down
Stop-CsWindowsService -Graceful
CMS Database
Lync SE – dont need to define server FQDN (generally this is done by prep first SE)
Lync EE
Install-CsDatabase -CentralManagementDatabase -SqlServerFqdn <server FQDN>
Install-CsDatabase -CentralManagementDatabase -SqlServerFqdn <sqlbe FQDN> -SqlInstanceName rtc -DatabasePaths “D:CSDB-Logs”,”D:CSDB-Database”,
Can also be removed with
UnInstall-CsDatabase -CentralManagementDatabase -SqlServerFqdn <sqlbeFQDN>
enable-ummailbox -identity  –extensions 1234 -ummailboxpolicy DefaultUMPolicy –SIPResourceIdentifier
Test DHCP (using DHCPUtil.exe from the RESKit)
From directory where DHCPUtil.exe lives (could be copied to anywhere for convenience)
DHCPUtil.exe -emulateclientPhone Lock
set-CsUcPhoneConfiguration EnforcePhoneLock $false

Test Phone Number and PIN Login
Test-CsPhoneBootstrap -PhoneOrExt 1234 -PIN 10101 -verbose

Clear User Caching
set-csuser -identity -clearCacheOnNextSignIn:$true”

Skype Connectivity
Remove-CsPublicProvider -Identity MSN

New-CsPublicProvider -Identity Skype -ProxyFqdn -IconUrl “; -VerificationLevel 2 -Enabled 1

Lync 2013 New

Trusted applications and policy settings

Get-CsTrustedApplicationEndpoint -Identity “” | Select-Object *
Response Group Failover
Export-CsRgsConfiguration -FileName “” -Source service:applicationserver:<Lync FE FQDN>

Get all configuration overview
Get-CsService | out-file C:MyLyncConfiguration.txt
Get Current Call Volume (and other activity)
User Pool Assignment
get-csuserpoolinfo -identity

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s