donderdag 6 oktober 2011

Useful script to export OCS / Lync telephone nr's from AD

A couple of days ago I was asked if I could export all the telephone numbers from AD used by OCS.
As far as I know OCS does not have this capability out of the box ( unfortunately ).
Using my friend 'google' did not find a usable script either.

With some trial and error I managed to create a scipt to export al the numbers to a csv. ( Actually its not really a script but a single line :) )

I used the free powershell commands for Active Directory by Quest. U can probably get the same results with standard powershell, but I found more useful examples for the Quest powershell.
The powershell command for AD by Quest can be downloaded here.

I downloaded the 64 bit MSI version which is about 33 MB.

After installation, the ActiveRoles Management Shell for Active Directory can be found in the start menu under Quest Software.

The attribute we want to export is msRTCSIP-Line.
This attribute contains the telephone number configured in OCS or Lync.
We want powershell to show us all the users where this attribute had a value.
For this we use an Ldap filter for the attribute msRTCSIP-Line and use a wildcard for a value.

Output of this command gives us a list of users where the attribute msRTCSIP-Line had a value.
But what we want is to see the users displayname and the number for that user.

To accomplish this we have to use a couple of extra parameters.
First, we want to include the value of the attribute msRTCSIP-Line.
So we use the parameter -includedproperties to include the value of the attribute.
Second, we select which attributes we want to show in our list, and last we tell powershell to show the output in a list.
In this example I chose only the displayname and the telephone number to be shown in our list.
U can add / set every attribute u want to show, for example u can add the officelocation or OU.

When performing the command you will see the output on your screen.

To export the values to a csv, we have to replace the | fl for an | Export-Csv -path {path}
If we want to save the csv to c:\scripts\telephonenrsOCSusers.csv for example, we add | Export-Csv -path c:\scripts\telephonenrsOCSusers.csv.

Our final command should look like this.

And there you have it, the csv is saved in the chosen folder.

For the copy pasters amung us :

Get-QADUser  -LDAPFilter '(&(msRTCSip-Line=*))' -IncludedProperties 'msRTCSIP-Line' | Select-Object displayName, msRTCSIP-Line, physicalDeliveryOfficeName | Export-Csv -Path c:\scripts\telephonenrsOCSusers.csv


1 opmerking: