PS One Liners

A collection of useful Scripts and commands

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

Get Last Logon Time for all Skype for Business Users

$SFBUsers = get-csuser

foreach ($user in $SFBUsers){

get-aduser $user.SamAccountName -properties * | Select-Object Name, @{ Name = “Stamp”; Expression = { [DateTime]::FromFileTime($_.lastLogon).ToString(‘yyyy-MM-dd’) } }


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 and Meeting Rooms

Enable all users in an OU for Lync
get-csADuser -OU “OU=Users,OU=Auckland,dc=ucsorted,dc=com” | 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=ucsorted,dc=com” | 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 “”

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 “C:\”

Who is federating with me?
Get-EventLog “lync server” | ? {$_.eventid -eq 14601} | Select eventid,message -First 1 | fl *

Unassigned Numbers routed to IVR (No announcement in this case)
New-CsAnnouncement -Parent service:ApplicationServer: -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: -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 Number
Set-CsUser -Identity “” -PrivateLine “Tel:+6499502534”.
Removing Private Lines
Set-CsUser -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=ucsorted,dc=com” | Grant-CsVoicePolicy -PolicyName “SIP Voice Policy”

Get numbers stored in AD
get-aduser – -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
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

Extending the Distribution Group Expansion size limit
Set-CsWebServiceConfiguration – Shows current limit (default 100)
Set-CsWebServiceConfiguration -maxgroupsizetoexpand 200

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 minutes
Finding Contact Merge issues

Export AddressBook

.\abserver.exe -dumpfile “C:\LyncShare\1-WebServices-1\ABFiles0000000-0000-0000-0000-0000000000000000000-0000-0000-0000-000000000000\F-13cc.lsabs” c:\temp\Export-ABS.txt

Graceful Shut Down
Stop-CsWindowsService -Graceful

Installation of Windows Identity Foundation

Add-WindowsFeature Windows-Identity-Foundation

CMS Database
Lync SE – dont need to define server FQDN (generally this is done by prep first SE)

Lync EE
Install-CsDatabase -CentralManagementDatabase -SqlServerFqdn
Install-CsDatabase -CentralManagementDatabase -SqlServerFqdn -SqlInstanceName rtc -DatabasePaths “D:\CSDB-Logs”,”D:\CSDB-Database”,

Can also be removed with
UnInstall-CsDatabase -CentralManagementDatabase -SqlServerFqdn

Testing CsDatabase

Test-CsDatabase -ConfiguredDatabases | ft databasen*,Expe*,Inst*,Suc* -AutoSize

Enable UM
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 -emulateclient
Phone 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 Consumer Connectivity (Lync 2010\2013 &SFB)
Remove-CsPublicProvider -Identity MSN

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

NOTE The Edge Server for Federation needs to have access to on Port 443

Lync 2013 New

Trusted applications and policy settings
Get-CsTrustedApplicationEndpoint -Identity “” | Select-Object *

Response Group Failover
Export-CsRgsConfiguration -FileName “c:\” -Source service:applicationserver:

Hide Response Group from AddressBook

Get-ADObject -SearchBase “CN=Application Contacts,CN=RTC Service,CN=Services,CN=Configuration,DC=ucsorted,DC=com” -Filter {msRTCSIP-PrimaryUserAddress -eq “”} | Set-AdObject -replace @{msExchHideFromAddressLists=$true}

OR Hide a selection based on a filter

Get-ADObject -SearchBase “CN=Application Contacts,CN=RTC
Service,CN=Services,CN=Configuration,DC=ucsorted,DC=com” -Filter {msRTCSIP-Prim
aryUserAddress -like “*”} | Set-AdObject -replace @{msExchHide

Get all configuration overview
Get-CsService | out-file C:\MyLyncConfiguration.txt

User Pool Assignment
get-csuserpoolinfo -identity

Finding orphaned users in SQL Database
Find the user in the database

SELECT [ResourceId],[UserAtHost] FROM [rtc].[dbo].[Resource]Where UserAtHost =  ‘

Remove the User form the database (do this on all SQL Databases)
dbo.RtcDeleteResource ”

Mobility – Enabling Push Notification
Set-CsPushNotificationConfiguration -EnableApple
PushNotificationService $true -EnableMicrosoftPushNotificationService $true

Skype Directory Button Mission

Remove-CsPublicProvider -Identity Skype
New-CsPublicProvider -Identity Skype -ProxyFqdn -IconUrl -NameDecorationRoutingDomain -NameDecorationExcludedDomainList “,,,” -VerificationLevel UseSourceVerification -Enabled $True -EnableSkypeDirectorySearch $True -EnableSkypeIdRouting $True

Testing Databases

Test-CsDatabase -ConfiguredDatabases | ft databasen*,Expe*,Inst*,Suc* -AutoSize

Setting Windows Fabric log files to circular to avoid disk bloat. Run from elevated CMD

Logman update trace FabricLeaseLayerTraces -f bincirc –cnf



1 thought on “PS One Liners”

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 )

Facebook photo

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

Connecting to %s