I find myself having to create and use the same Lync Powershell scripts over and over again, so I thought I'd compile a list of some of the ones I've created for others. It will get updated as time goes on.
Enjoy, and suggest others in the Comments.
Finding all the people who have a telephone number set in Lync
Get-CsUser -Filter {LineURI -ne $NULL} | FT Name, LineURI
Change SIP domain for all users
$UserList = Get-CsUser
foreach ($User in $UserList)
{
$oldAddress = $User.SipAddress
$newAddress = $oldAddress -replace "@olddomain.com", "@newdomain.com"
Set-CsUser -Identity $User.Identity -SipAddress $newAddress
}
Setting the AD office phone number to the TelURI for all users
#Only need to add the AD Powershell instance once
Add-WindowsFeature RSAT-AD-Powershell
Import-Module ActiveDirectory
$users = Get-CSUser
Foreach ($user in $users)
{
$Tel = $user.LineURI
$Tel = $Tel.Replace("tel:", "")
If ($Tel -ne "")
{
Set-ADUser -Identity $user.SAMAccountName -OfficePhone $Tel
}
}
Move All OCS Users Homed on a Specific Pool to Lync
Also sets conferencing policy and external access policy to automatic, rather than the legacy migrated OCS policies. Replace items in bold with your environmental specifics.
get-csuser -OnOfficeCommunicationServer | Where {$_.HomeServer -eq "CN=LC Services,CN=Microsoft,CN=OCSPOOLNAME,CN=Pools,CN=RTC Service,CN=Services,CN=Configuration,DC=contoso,DC=com"} | Move-CsLegacyUser -Target LYNCPOOLFQDN -ExcludeConferencingPolicy -ExcludeExternalAccessPolicy -Confirm:$FALSE
Count How Many Users are on OCS and Lync
(Get-CsUser -OnOfficeCommunicationServer).Count
(Get-CsUser -OnLyncServer).Count
Get a List of All Lync-Enabled Users Along with Selected AD Properties
#Asked by a commenter. Harder than it initially looked....
$ErrorActionPreference = 'SilentlyContinue'
Import-Module ActiveDirectory
$Output = @()
Foreach ($LyncUser in Get-CSUser -ResultSize Unlimited)
{
$ADUser = Get-ADUser -Identity $LyncUser.SAMAccountName -Properties Department, Title
$Output += New-Object PSObject -Property @{DisplayName=$LyncUser.DisplayName; Department=$ADUser.Department; Title=$ADUser.Title; SAMAccountName=$ADUser.sAMAccountName; SIPAddress=$LyncUser.SIPAddress; EVEnabled=$LyncUser.EnterpriseVoiceEnabled}
}
$Output | Export-CSV -Path .\Output.csv
$Output | FT DisplayName, Title, Department, SAMAccountName, SIPAddress, EVEnabled
Create Lync Network Sites and Subnets using Info from AD Sites & Services
http://ucken.blogspot.ca/2013/04/automatically-creating-lync-sites-and.html
Thanks for the above examples Ken, I am wondering if you have ever tried using the -LdapFilter parameter. In specific, I wanted to get a list of all of the users display names, sam account names sip address and if they were enabled for enterprise voice or not. I ran ve Get-CsUser | Format-Table -Property DisplayName, SamAccountName, SipAddress, EnterpriseVoiceEnabled -
ReplyDeleteAutoSize
In addition I wanted to get all of their AD related information such as department, title address and such information too. And from what I can see it can be done using the -LdapFilter Parameter but I can't find any working examples of it. Any pointers will be helpful.
Thanks.
Jawad,
DeleteThe LDAPFilter is only used to filter results based on a specified criteria, like Show only users who reside in Las Vegas. It doesn't do anything for actually displaying information. To get both Lync information and AD information, you need to combine the results from 2 commands. See my newly added sample called "Get a List of All Lync-Enabled Users Along with Selected AD Properties"
Ken
Uhmmm...hope I am not double posting here, was supposed to reply to my own comment With an edit to a typo but it seems that it actually replaced my original one.
ReplyDeleteI was trying to point out that you could rather apply the "Filter" parameter of the Get-CsUser cmdlet, like
Get-CsUser -Filter (LineURI -ne "") | ft Name,Lineuri
This looks a little cleaner, and also leaves the filtering job to the Front End server if you are running the command from elsewhere - keeping unwanted results off the network.
Great blog btw!
Brgds,
Rune