We help IT Professionals succeed at work.

Powershell script that can enable OCS for the users whose names are in the excel colum "C"

Hi,

Powershell script that can enable OCS for the users whose names are in the excel colum "C"
Even enable the federation and all others as well.

Regards
Sharath
Comment
Watch Question

Adam BrownSenior Systems Admin
Top Expert 2010

Commented:
This should get you what you need: http://social.microsoft.com/Forums/en/communicationsserversetup/thread/c998bb23-6773-494d-81b6-c4eafde739e1

You'll need to modify the code to fit your environment a little.
Meir RivkinFull stack Software Engineer

Commented:
OCS  ??
Meir RivkinFull stack Software Engineer

Commented:
u mean Office Communications Server ?

Author

Commented:
Yes
Meir RivkinFull stack Software Engineer

Commented:
to enable particular user for OCS from column "C" in excel c:\temp\users.xls:
function Release-Ref ($ref) {
([System.Runtime.InteropServices.Marshal]::ReleaseComObject(
[System.__ComObject]$ref) -gt 0)
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
}
# -----------------------------------------------------

$objExcel = new-object -comobject excel.application 
$objExcel.Visible = $True 
$objWorkbook = $objExcel.Workbooks.Open("C:\temp\users.xls")
$objWorksheet = $objWorkbook.Worksheets.Item(1)

$intRow = 2

Do {
    $user = $objWorksheet.Cells.Item($intRow,3).Value()
	get-wmiobject -class MSFT_SIPESUserSetting | where-object { $_.PrimaryURI -eq $user } | % { $_.Enabled = $True; $_.put() | out-null }
    $intRow++
}
While ($objWorksheet.Cells.Item($intRow,1).Value() -ne $null)

$objExcel.Quit()

$a = Release-Ref($objWorksheet)
$a = Release-Ref($objWorkbook)
$a = Release-Ref($objExcel)

Open in new window

Meir RivkinFull stack Software Engineer

Commented:
regarding the OCS issue, check here for alternatives:
http://blog.insideocs.com/2009/01/16/189/

Author

Commented:
Thanks
I get this.
Where should i mention the Server name it needs to create OCS account
[PS] D:\>function Release-Ref ($ref) {
>> ([System.Runtime.InteropServices.Marshal]::ReleaseComObject(
>> [System.__ComObject]$ref) -gt 0)
>> [System.GC]::Collect()
>> [System.GC]::WaitForPendingFinalizers()
>> }
>> # -----------------------------------------------------
>>
[PS] D:\>$objExcel = new-object -comobject excel.application
[PS] D:\>$objExcel.Visible = $True
[PS] D:\>$objWorkbook = $objExcel.Workbooks.Open("D:\users.xls")
[PS] D:\>$objWorksheet = $objWorkbook.Worksheets.Item(1)
[PS] D:\>
[PS] D:\>$intRow = 2
[PS] D:\>
[PS] D:\>Do {
>>     $user = $objWorksheet.Cells.Item($intRow,3).Value()
>>     get-wmiobject -class MSFT_SIPESUserSetting | where-object { $_.PrimaryURI -eq $user } | % { $_.Enabled = $True; $
_.put() | out-null }
>>     $intRow++
>> }
>> While ($objWorksheet.Cells.Item($intRow,1).Value() -ne $null)
>>
Get-WmiObject : Invalid class
At line:3 char:18
+     get-wmiobject <<<<  -class MSFT_SIPESUserSetting | where-object { $_.PrimaryURI -eq $user } | % { $_.Enabled = $T
rue; $_.put() | out-null }
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

[PS] D:\>$objExcel.Quit()
[PS] D:\>
PS>$a = Release-Ref($objWorksheet)
[PS] D:\>$a = Release-Ref($objWorkbook)
[PS] D:\>$a = Release-Ref($objExcel)

Open in new window

Full stack Software Engineer
Commented:
try this instead
function Release-Ref ($ref) {
([System.Runtime.InteropServices.Marshal]::ReleaseComObject(
[System.__ComObject]$ref) -gt 0)
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
}
# -----------------------------------------------------
cls

$objExcel = new-object -comobject excel.application 
$objExcel.Visible = $True 
$objWorkbook = $objExcel.Workbooks.Open("C:\temp\users.xls")
$objWorksheet = $objWorkbook.Worksheets.Item(1)

$intRow = 2

Do {
    $user = $objWorksheet.Cells.Item($intRow,3).Value()
	
	$oa = @{'msRTCSIP-ArchivingEnabled'=0; 'msRTCSIP-FederationEnabled'=$true; 'msRTCSIP-InternetAccessEnabled'=$true; 'msRTCSIP-PrimaryUserAddress'=("sip:$Fullname@ourdomain.com"); 'msRTCSIP-UserEnabled'=$true }
	Set-QADUser $user -oa $oa

    $intRow++
}
While ($objWorksheet.Cells.Item($intRow,1).Value() -ne $null)

$objExcel.Quit()

$a = Release-Ref($objWorksheet)
$a = Release-Ref($objWorkbook)
$a = Release-Ref($objExcel)

Open in new window

Author

Commented:
Where should i mention which server it needs to create
Meir RivkinFull stack Software Engineer

Commented:
u didn't mention in the question creating server...
what do u mean?

Author

Commented:
Sorry
Say i have 5 OCS servers
I want these users to be created in 1 specific server
Then we need to select which server i need to create
Meir RivkinFull stack Software Engineer

Commented:
can u run the script on the server in which u want to enable OCS to user?