Here’s an ad-hoc post with a collection of snippets of PowerShell I often seem to find myself needing to refer to.
There are some more good ones here from Paul Bloem, over the pond.
How do I find (and/or count) the users homed to a given FE/pool?
Get-CsUser | Where-Object {$_.RegistrarPool -match "<POOL FQDN>"} | measure
How about the users still on OCS?
Get-CsUser -OnOfficeCommunicationServer | Measure
How can I count the number of users who are enabled for Enterprise Voice?
Get-CsUser | Where-Object {$_.EnterpriseVoiceEnabled -match "true"} | measure
… or a combo: who’s on this pool AND enabled for Enterprise Voice?
Get-CsUser -filter {registrarpool -eq "<POOL FQDN>"} | where-object {$_.EnterpriseVoiceEnabled -match $True} | ft DisplayName,SipAddress,LineUri,RegistrarPool >> EV-userlist.txt
How do I find and relocate all of the Lync users in a given OU?
Get-CsUser -OU "OU=Users,OU=Sydney,OU=australia,DC=contoso,DC=com,DC=au" | Move-CsUser –Target lync2013pool.contoso.com.au –verbose
How can I find out who’s using a particular number? (NB: this isn’t going to reveal if the number’s being used by a Response Group, a Private Line, Analog or Common Area phone)
Get-CsUser | ?{$_.LineURI –like “Tel:+61270001234”}
How can I find if/what Common Area (or Analog) phone is using a particular number?
Get-CsCommonAreaPhone | where-object {$_.lineuri -like "*1234*"}
How do I create objects using values from a CSV file?
import-csv "C:\CommonAreaPhones.csv" | foreach {New-CsCommonAreaPhone -RegistrarPool lync2013pool.contoso.com.au -OU "ou=Service Accounts,dc=contoso,dc=com,dc=au" -DisplayNumber $_.DisplayNumber -DisplayName $_.Name -LineURI $_.LineURI } -verbose > c:\CommonAreaPhones-results.txt
Check for everyone who’s not yet set a dialin conferencing PIN and set one for them
get-csuser | Get-CsClientPinInfo | Where-Object {$_.IsPinSet -match "False"} | measure get-csuser | Get-CsClientPinInfo | Where-Object {$_.IsPinSet -match "False"} | Set-CsClientPin -Pin "1234"
How do I find where the CMS is located?
Get-CsConfigurationStoreLocation
How do I see ALL of the members of an array? (Refer this post)
PS > $FormatEnumerationLimit 3 PS > $FormatEnumerationLimit=-1
How do I get PowerShell to spit an error when I ask for objects or properties that don’t exist, rather than just output a blank line?
Set-StrictMode –Version "Latest" Set-StrictMode –off
(Strict mode can be REALLY helpful when you’re fishing around in the dark trying to cobble together a funky command string and aren’t sure if the null outputs are empty values, or you’re asking for stuff that doesn’t exist). (Credit).
I have a VAST deployment. I only want to see the servers that aren’t replicating:
Get-CsManagementStoreReplicationStatus | Where-Object {$_.UpToDate -eq $False}
Restart any stopped Lync services (thanks Pat):
Get-CsWindowsService -ExcludeActivityLevel | ? {$_.Status -like "Stopped"} | Start-CsWindowsService
Not strictly *Lync* PowerShell, this will tell you the version of all the installed Lync components. (It’s the PowerShell equivalent of running ServerUpdateInstaller.exe from a CU to see what CU you’re currently at). [I’ve seen this posted HERE and HERE, and I don’t know who the original author is. Credit to you, whoever you may be!]
Get-WmiObject –query ‘select * from win32_product’ | where {$_.name –like “Microsoft Lync Server*”} | ft Name, Version –AutoSize
G.
Hi, great article. I would recommend to use he -filter capabilities of the cmdlets though. Should be much faster. Example: get-csuser -filter {Registrarpool -eq “pool1.contoso.com”} | measure-object. Try it out.
Hi Paul-Christiaan.
Thanks for the suggestion. I’ve found “-filter” often doesn’t work, so I’ve largely abandoned it in favour of the more reliable “Where-Object”.
I even blogged it a while back: https://greiginsydney.com/powershell-filter-command-fails/
G.