Just so you Perl fans don't get upset, you can find the Perl version of this script in the article - Reading a User's OCS Properties with a Perl Script.
The script takes the user name as a command line argument. It can be the cn, samAccountName, or displayname of the user. Use quotes around any user name that contains a space. If the user name is omitted, the script will get the OCS properties of the currently logged on user. To run the script, save the code in a file such as getOCSproperties.ps1 and run it from within PowerShell, as shown:
The script uses the System.DirectoryServices.DirectorySearcher to find the user, then retrieves the user's OCS attributes. As for the policies, which is an (or an array of) DNwithBinary objects, they have to be broken down into their BinaryValue (which tells us what type of policy it is), and the DNString (which holds the distinguished name of the policy object itself). We then get the policy object and retrieve the policy content, which is a piece of XML. We can then dig the name of the policy out of the XML and display the policy name and type in the output. Finally the script breaks down the option flags by bit and displays their status.
By the way, we show how to handle the policies in Perl and VBScript in the articles: msRTCSIP-UserPolicy - Here's How to Read it and msRTCSIP-UserPolicy - Here's How to Write it.
Those articles show how to handle the DNWithBinary objects, but Perl and VBScript access those objects directly via COM. PowerShell on the other hand, accesses these COM objects through a .Net interop assembly. Unfortunately, interop lacks the information to handle this type of COM object, so we have to bypass interop by making a direct call to COM, using [System.__ComObject].InvokeMember. We also use this technique to get the username property from the adsysteminfo object in the beginning of the script to get the currently logged on user.
Stay tuned for more PowerShell examples, and we'll start posting Lync scripts as soon as our environment is setup!