Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Thursday, December 11, 2014

Some Useful PowerShell One Liners for Lync

Useful PowerShell One-Liners for Lync

Below are some one-liners I use often in administering Lync systems, so I thought I would share this as a reference. These should be run from a Lync PowerShell Instance, unless otherwise indicated:

List a User's Response Group Memberships
get-csrgsagentgroup | Where-Object {$_.AgentsByUri -like "sip:first.last@domain.com"} | Select name

Get users in specific OU and output to csv (run from Exchange Powershell)
get-mailbox -OrganizationalUnit "ou=YourOU,dc=DOMAIN,dc=COM" -resultsize unlimited | select-object DisplayName,SamAccountName,PrimarySmtpAddress | Export-CSV e:\files\DomainUsers.csv

Invoking CMS Replication
Invoke-CSManagementStoreReplication

Getting CMS Replication Status of only Lync Servers
Get-CsManagementStoreReplicationStatus | Where-Object {$_.ReplicaFqdn -match "ServerNamingConvention" -Or $_.ReplicaFqdn -match "SBANamingConvention"} | Select ReplicaFqdn, UpToDate

Get users where External Access is…
get-csuser | Where {$_.ExternalAccessPolicy -like "PolicyName"}

Counting users who have a telephone number set in Lync
get-csuser | Sort-Object LineURI | where {$_.LineURI -ne ""} | Measure-Object

Finding AD Disabled Accounts Who are Still Lync Enabled
Get-CsAdUser | ?{$_.UserAccountControl -match "AccountDisabled" -and $_.Enabled -eq $true} | ft Name,Enabled,SipAddress -auto

Counting AD Disabled Accounts Who are Still Lync Enabled
Get-CsAdUser | ?{$_.UserAccountControl -match "AccountDisabled" -and $_.Enabled -eq $true} | Measure-Object

List all users in a pool
get-csuser | where-object {$_.RegistrarPool -like "lyncpoolfqdn"}  | Select-Object DisplayName, LineUri

List all Common Area Phones in a pool
get-cscommonareaphone | where-object {$_.RegistrarPool -like "lyncpoolfqdn"}  | Select-Object DisplayName, LineUri

List all Analog Devices in a pool
get-csanalogdevice | where-object {$_.RegistrarPool -like "lyncpoolfqdn"} | Select-Object DisplayName, LineUri

Count How Many Users are on Lync
(Get-CsUser -OnLyncServer).Count

Get PowerShell Version (run from any PowerShell Session)
$PSVersionTable.PSVersion.Major
Or
Get-Host | Select-Object Version

Getting Relative Dates (run from any PowerShell Session)
Here's a quick and fast way of generating relative dates in any format:
(Get-Date).AddDays(-1).ToString('yyyy-MM-dd')<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office"/>

This returns all error events from the System event log in the past 48 hours: (run from any PowerShell Session)

Get-EventLog -LogName System -EntryType Error -After (Get-Date).AddDays(-2)

I'll add more as need arises. Hope these are helpful.

Friday, March 15, 2013

List A User's Response Group Memberships

We just had an issue where a response group in Lync was not working properly. While troubleshooting, we discovered that the user to whom the response group pointed had recently been married and had her name changed. Per normal process, her AD account, email address and SIP name were changed to her new name. This caused an issue with the response group, however. Since there was a gap in the process, and we had no procedure in place for checking the user’s membership in response groups, the group was trying to transfer a call to a now non-existent SIP address. So, that means whenever we change an account we must know if the user is Enterprise Voice enabled, and if they are, we must also know if they belong to any response groups. Unfortunately, there is no clean way to find that membership in the Lync Control Panel. You would have to open each response group and look at its membership one at a time to see if the user was a member. To get around this, you’ll have to RDP into a Lync  Server and open a Lync Powershell session and enter the following command:

get-csrgsagentgroup | Where-Object {$_.AgentsByUri -like "sip:first.last@spx.com"} | Select name

See the example below to illustrate what it looks like and what the results would be:
This will give you a list of response groups the user is a member of. You can then make the appropriate changes to the groups, if any.

Thursday, August 9, 2012

Enabling users for Lync Enterprise Voice

I am now piloting Lync Enterprise Voice for my company, and we will be enabling many users moving forward. I have written the following script to:
  1. Move users to a "Branch" Pool
  2. Enable them for Voice
  3. Grant a voice policy
The script is meant to be run, eventually, by local IT at the branch location. It takes input from a .csv file structured like:

LineURI,Name,ADUSERNAME
tel:+11112345678;ext=5678,Jon Smith,jsmith
tel:+11112347485;ext=7485,Nasir Patel,npatel
tel:+11112347518;ext=7518,Tom Jones,tjones


You can tailor the LineURI as appropriate for your organization.

The script, when launched, asks for the target pool, the file with the information and the voice policy to be granted:




That's all you need to do. Well, that and then enable them in whatever voicemail solution you are employing...

The code is as follows. I will make it more elegant as time allows.

<# 
.SYNOPSIS 
  Queries admin for Pool, Input File and Voice Policy for the users. Then
  reads info in Input file, moves users to appropriate pool, enables Enterprise
  Voice for them, and grants the entered Voice Policy.

.NOTES 
    Version           : 1

      Lync Version  : 2010 through CU6
    Author(s)      : Sean William McNamara (
sean.mcnamara@spx.com)
    Dedicated Post  :
http://unicomsta.blogspot.com/
    Disclaimer     : Test thoroughly and use at your own risk. If you don't test it, and you break stuff, it isn't MY fault.
   
.LINK 
    http://unicomsta.blogspot.com/2012/08/enabling-users-for-lync-enterprise-voice.html

.EXAMPLE
  .\Enable-EvUsers.ps1
#>
#initialize variables
$poolfqdn = read-host "Enter new pool FQDN to move users to "
$InputFileName = read-host "Enter filename for user data "
$VoicePolicy = read-host "Enter Voice Policy Name "


#read data for Accounts
$AccountData = Import-Csv $InputFileName

#move users to correct registrar pool
foreach ($item in $AccountData)
{ write-host -fore yellow "Moving" $item.NAME "... "
  move-csuser -identity $item.ADUSERNAME -target $poolfqdn -confirm:$false
}

write-host
write-host -fore green "Move completed"
write-host
#enable EV and set URI

foreach ($item in $AccountData)
{ write-host -fore yellow "Enabling Voice for " $item.NAME "... "
  Set-CsUser -Identity $item.adusername -EnterpriseVoiceEnabled $true -LineURI $item.LineURI
}

write-host
write-host -fore green "Enterprise Voice Enabled"
write-host

#grant Voice Policy
foreach ($item in $AccountData)
{ write-host -fore yellow "Granting Voice Policy "$VoicePolicy" to " $item.NAME " ... "
  Grant-CsVoicePolicy -Identity $item.adusername -PolicyName $VoicePolicy
}

write-host
write-host -fore green "Voice Policies Granted"
write-host