Answered by:
How to remove contacts group for all users?

Question
-
Hi,
I am using the LCSAddCotacts.wsf script from the OCS ResKit to manage (add/remove) contacts for OCS Enabled users in our company.
Using the "/cotactsgroup" switch I am able to group contacts into contacts groups which comply to departments in our organizational structure.
What I would like to know is how to remove contacts group for all users.
LCSAddContacts.wsf provides only the ability to add / remove contacts, but what about contacts groups?
Thanks a lot,
Vedran Matica
Monday, July 14, 2008 1:24 PM
Answers
-
You should probably dive into Communication Server 2007 WMI programming
http://msdn.microsoft.com/en-us/library/bb632098.aspx
MSFT_SIPESUserContactGroupData
DeleteInstance();- PutInstance();
You should be able to get the group by doing something similar like this
(I have not verified this code)
sComputer =
sUserInstanceID =
sGroupName =
Set oInstances = GetObject("winmgmts:\\" & sComputer).ExecQuery("SELECT * FROM " & cWMIUserContactGroupClass & " WHERE UserInstanceID = '" & sUserInstanceID "'")
If Not oInstances.Count < 1 Then
For Each oInstance In oInstances
wscript.echo oInstance.Name
If StrComp(Name, oInstance.Name) = 0 Then
oInstance.DeleteInstanceEnd If
End If
NextWednesday, July 30, 2008 9:53 PM
All replies
-
You should probably dive into Communication Server 2007 WMI programming
http://msdn.microsoft.com/en-us/library/bb632098.aspx
MSFT_SIPESUserContactGroupData
DeleteInstance();- PutInstance();
You should be able to get the group by doing something similar like this
(I have not verified this code)
sComputer =
sUserInstanceID =
sGroupName =
Set oInstances = GetObject("winmgmts:\\" & sComputer).ExecQuery("SELECT * FROM " & cWMIUserContactGroupClass & " WHERE UserInstanceID = '" & sUserInstanceID "'")
If Not oInstances.Count < 1 Then
For Each oInstance In oInstances
wscript.echo oInstance.Name
If StrComp(Name, oInstance.Name) = 0 Then
oInstance.DeleteInstanceEnd If
End If
NextWednesday, July 30, 2008 9:53 PM -
Hi,
Many thanks.
From the several resources found on the MSDN I have come up with a script which enumerates all of the users on the OCS server and displays the list of contacts groups per each user.
It can be further enhanced to delete specific groups by using the DeleteInstance() method of the MSFT_SIPESUserContactGroupData class.
Thanks,
Vedran Matica
On Error Resume Next
strComputer = "OCSSERVER"
Set wmiServer = CreateObject("WbemScripting.SWbemLocator").ConnectServer()
Query = "SELECT * FROM MSFT_SIPESUserSetting"
Set LCUserEnum = wmiServer.ExecQuery(Query)For each LCUser in LCUserEnum
WScript.Echo LCUser.InstanceID & " " & LCUser.DisplayName
strUID = LCUser.InstanceID
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM MSFT_SIPESUserContactGroupData WHERE UserInstanceID = '"& strUID &"'")For Each objItem In colItems
WScript.Echo "ExternalURL: " & objItem.ExternalURL
WScript.Echo "GroupID: " & objItem.GroupID
WScript.Echo "Name: " & objItem.Name
WScript.Echo "************"
Next
Wscript.echo
WScript.Echo "************************************"
Wscript.echo
Next
ObtainLCUserInstanceID = trueTuesday, August 12, 2008 12:04 PM -
Thank you for that script to enumerate groups per user.
I am trying to expand on the script to allow for mass deletion of an OCS group. We had some organizational shifts so I had to rename OCS groups to match new OU names. I am running into an issue...I get the following error, probably because I am using the method incorrectly (I need help on that.)
I tied some file dump code so I can audit what happens. I also removed "On Error Resume Next" so the errors pop up.
Code SnippetObject doesn't suppoer this property or method: 'objItem.DeleteInstance'
I tried with both objItem and colItems, but neither works (same error.)
Please see the code I am trying below:
Code SnippetDim oFilesys, oFiletxt, sFilename, sPath
Set oFilesys = CreateObject("Scripting.FileSystemObject")
Set oFiletxt = oFilesys.CreateTextFile("c:\delgroups.txt", True)
sPath = oFilesys.GetAbsolutePathName("c:\delgroups.txt")
sFilename = oFilesys.GetFileName(sPath)
strComputer = "myocsfrontendserver.domain.local"Set wmiServer = CreateObject("WbemScripting.SWbemLocator").ConnectServer()
Query = "SELECT * FROM MSFT_SIPESUserSetting"
Set LCUserEnum = wmiServer.ExecQuery(Query)For each LCUser in LCUserEnum
oFiletxt.WriteLine(LCUser.InstanceID & " " & LCUser.DisplayName)
strUID = LCUser.InstanceID
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM MSFT_SIPESUserContactGroupData WHERE UserInstanceID = '"& strUID &"'")For Each objItem In colItems
oFiletxt.WriteLine("ExternalURL: " & objItem.ExternalURL)
oFiletxt.WriteLine("GroupID: " & objItem.GroupID)
oFiletxt.WriteLine("Name: " & objItem.Name)
If objItem.Name = "GROUP-I-WANT-TO-DELETE" Then
oFiletxt.WriteLine("Deleting Group:" & objItem.Name)
objItem.DeleteInstance()
End If
oFiletxt.WriteLine("************")
Next
oFiletxt.WriteLine(" ")
oFiletxt.WriteLine("************************************")
oFiletxt.WriteLine(" ")
Next
oFiletxt.Close
ObtainLCUserInstanceID = trueTuesday, November 11, 2008 1:37 AM