# this powershell snippet defines a function which will OCS enable the supplied AD account # it also enables the user for Enhanced Presence Function EnableOCSUser { Param([String]$URI, [String]$UserDN, [String]$OCSHomeServerDN) #-------------------------------------------------- INPUT -------------------------------------------- # $URI = the primary user SIP address (e.g. user@domain.com) # $UserDN = the distinguished name of the corresponding Active Directory user object for this user. # e.g. CN=FirstName LastName,OU=Employees,DC=contoso,DC=com} # $OCSHomeServerDN = # The distinguished name of the OCS pool or server for this user as shown in AD. # e.g. CN=LC Services,CN=Microsoft,CN=,CN=Pools,CN=RTC Service,CN=Services,CN=Configuration,DC=contoso, DC=com #-------------------------------------------------------------------------------------------------------- Write-Host "About to OCS enable the following user:" Write-Host "`t $URI" Write-Host "`t $UserDN" Write-Host "`t $OCSHomeServerDN" Write-Host "" # add "SIP:" prefix to the URI if not already specified if ($URI.Substring(0,4).toupper() -ne 'SIP:') {$URI = "SIP:$URI"} # make sure OCS WMI instance for this Primary URI doesn't exist already $WQL = "Select * From MSFT_SIPESUserSetting where PrimaryURI='$URI'" $newUserObject = Get-wmiObject -query $WQL if ($newUserObject -ne $null) { write-error "OCS user object already exists for: $URI. Aborting.`n" write-host exit } $newUserObject = $null # create the new OCS user $newOCSUser = ([wmiclass]"\\.\root\cimv2:MSFT_SIPESUserSetting").createinstance() if ($newOCSUser -eq $null) { write-Host "OCS user WMI object is null"} $newOCSUser.Enabled = $true # OCS Enables the user $newOCSUser.PrimaryURI = $URI $newOCSUser.UserDN = $UserDN $newOCSUser.HomeServerDN = $OCSHomeServerDN $newOCSUser.EnabledForEnhancedPresence = $true $newOCSUser.Put() | out-null # user OCS WMI instance should exist now; check to make sure $WQL = "Select * From MSFT_SIPESUserSetting where PrimaryURI='$URI'" $newUserObject = Get-wmiObject -query $WQL if ($newUserObject -eq $null) { write-Host "OCS user object creation failed"} else { Write-Host "AD user successfully OCS enabled" $newUserObject } } # call the above powershell function to enable the user for OCS # > ** fill in the appropriate values here ** EnableOCSUser "SIP:ExampleUser@example.com" "CN=Example User,CN=Users,DC=example,DC=com" "CN=LC Services,CN=Microsoft,CN=pool1,CN=Pools,CN=RTC Service,CN=Services,CN=Configuration,DC=dc,DC=example,DC=com" # gotcha's #Exception calling "Put" with "0" argument(s): "Exception calling "Put" with "0" argument(s): """ #> almost always, one of your parameters is not correct, or the OCS WMI object already exists for that user