Home > OCS 2007 / Lync 2010, Powershell > OCS 2007 R2: Get OCS contacts with Powershell and WMI

OCS 2007 R2: Get OCS contacts with Powershell and WMI

It is apparently also possible to manage OCS tasks by using WMI and Windows PowerShell. In this post I will cover how to get contacts of a specific user account. This task is unfortunately not possible via the OCS GUI Console. This is in analog to my previous post where I already covered how to extract a contactlist via the “Dbimpexp.exe” which is included in the OCS 2007 Resource Kit.

Get OCS contacts with Powershell and WMI:

$User = Get-WmiObject -Query "Select * from MSFT_SIPESUserSetting where PrimaryURI = 'sip:example@testdomain.com'"
$UserInstanceID = $User.InstanceID
$Contacts = Get-WmiObject -Query "Select * from MSFT_SIPESUserContactData where UserInstanceID = '$UserInstanceID'"
$displaycontacts = $Contacts | select SIPURI
Write-Output $displaycontacts

First you need to find the corresponding UserInstanceID of the SIP URI via the  MSFT_SIPESUserSetting WMI Class. In the second part of the script you can get the contacts from the MSFT_SIPESUserContactData Class with the UserInstanceID.

Output:

Get also the OCS Powerpack from PowerGUI to easily view the OCS WMI Classes:

Other interesting scripts can be found in the underneath technet blog:
http://blogs.technet.com/b/csps/archive/2010/11/15/r2manageusercontactlists.aspx

Advertisements
  1. alin
    February 22, 2011 at 8:21 pm

    Hi,

    This is all usefull information, but it would be even more usefull if there is some sql querry out there to retrive list of users who have at least a PIC(msn/yahoo/aol) contact in their buddy list…that is the post that i’m looking for!

    thanks
    A.

  2. Joris
    February 23, 2011 at 8:36 am

    I will try to make a script when I have some time to retrieve this information.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: