Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.

Update filters using All Collections in DIR.EXE???

Created: 20 Nov 2012 • Updated: 27 Oct 2013 | 2 comments
This issue has been solved. See solution.

Did anybody use this utility in version 6.x and if so, do you know if there is a comparable option in version 7.1SP2?  I need a method to update an entire folder of filters that are not tied to policies.  As always, any help would be greatly appreciated.

Comments 2 CommentsJump to latest comment

SaschaH's picture

You can use a Task with some ASDK magic inside. A combination of Item and CollectionManagement(Altiris.ASDK.NS.CollectionManagement/ItemManagement) will do the trick.

Give it a starting folder and call a recursive Function checking all the Items in a folder(GetItemsInFolder(GUID)) if they have the TypeName "PresentationFolder", if yes call the recursive function again with that Guid, else Call UpdateCollections with the Guid you have.

Check the ASDK Samples in the Altiris\Altiris ASDK\Samples\Notification Server\CollectionManagement Folder

Hope that gets you in the right direction.

Bechtle – your strong IT partner. Today and tomorrow

If that seems to help, please "Mark as Solution"

AngelD's picture

Utilizing the ASDK I would use something like this

Const TYPENAME_FILTER = "NSDataSrcBasedWithExplicitResourceCollection"
Const TYPENAME_FOLDER = "PresentationFolder"

Dim m_ItemManagement : Set m_ItemManagement = CreateObject("Altiris.ASDK.NS.ItemManagement")
m_ItemManagement.CreateLocalInstance()

Dim m_CollectionManagement : Set m_CollectionManagement = CreateObject("Altiris.ASDK.NS.CollectionManagement")
m_CollectionManagement.CreateLocalInstance()

Const FOLDER_GUID = "2815a982-348b-4d4b-92e9-45667e6c758a"

WScript.Echo "GetFiltersInFolderTree('" & FOLDER_GUID & "')"
LogItemInfo FOLDER_GUID
If (NOT GetFiltersInFolderTree(FOLDER_GUID, sFilterItemGuids)) Then
	WScript.Echo "Error -> GetFiltersInFolderTree() status=failed"
Else
	WScript.Echo "UpdateFilters('" & sFilterItemGuids & "')"
	If (NOT UpdateFilters(sFilterItemGuids)) Then
		WScript.Echo "Error -> UpdateFilters() status=failed"
	Else
		WScript.Echo UBound(Split(sFilterItemGuids, ","))+1 & " filters updated"
	End If

	For Each sItemGuid In Split(sFilterItemGuids, ",")
		LogItemInfo sItemGuid
	Next
End If

Sub LogItemInfo(ByVal sItemGuid)
	Dim oItem

	If (NOT GetItem(sItemGuid, oItem)) Then
		WScript.Echo "Error -> GetItem('" & sItemGuid & "') status=failed"
	Else
		WScript.Echo "Item (Name: '" & oItem.Name & "', Guid: '" & oItem.Guid & "', TypeName: '" & oItem.TypeName & "', ParentFolderGuid: '" & oItem.ParentFolderGuid & "')"
	End If
End Sub

Function GetFiltersInFolderTree(ByVal sFolderGuid, ByRef sGuidList)
	Dim sItemsGuids, sItemGuid
	GetFiltersInFolderTree = false
	sGuidList = ""

	If (GetItemsInFolderByType(TYPENAME_FILTER, sFolderGuid, sItemsGuids)) Then
		If (Len(sGuidList) = 0) Then
			sGuidList = sItemsGuids
		Else
			sGuidList = sGuidList & "," & sItemsGuids
		End If
	End If

	If (GetItemsInFolderByType(TYPENAME_FOLDER, sFolderGuid, sSubFolderGuids)) Then
		For Each sSubFolderGuid In Split(sSubFolderGuids, ",")
			If (GetFiltersInFolderTree(sSubFolderGuid, sItemsGuids)) Then
				If (Len(sGuidList) = 0) Then
					sGuidList = sItemsGuids
				Else
					sGuidList = sGuidList & "," & sItemsGuids
				End If
			End If
		Next
	End If

	If (Len(sGuidList) > 0) Then GetFiltersInFolderTree = true
End Function

Function GetItemsInFolderByType(ByVal sTypeName, ByVal sFolderGuid, ByRef sGuidList)
	Dim oFolderItems, oItem
	GetItemsInFolderByType = false
	sGuidList = ""
	
	If (NOT GetItemsInFolder(sFolderGuid, oFolderItems)) Then Exit Function
	
	For Each oItem In oFolderItems
		If (sTypeName = oItem.TypeName) Then
			If (Len(sGuidList) = 0) Then
				sGuidList = oItem.Guid
			Else
				sGuidList = sGuidList & "," & oItem.Guid
			End If
		End If
	Next
	
	If (Len(sGuidList) > 0) Then GetItemsInFolderByType = true
End Function

Function GetItemsInFolder(ByVal sFolderGuid, ByRef oItems)
	On Error Resume Next
	GetItemsInFolder = false
	
	Err.Clear
	oItems = m_ItemManagement.GetItemsInFolder("{" & sFolderGuid & "}")
	If ((Err = 0) AND (NOT IsNothing(oItems))) Then GetItemsInFolder = true
End Function

Function UpdateFilters(sFilterItemGuids)
	On Error Resume Next
	UpdateFilters = false

	Err.Clear
	m_CollectionManagement.UpdateCollections(sFilterItemGuids)
	If (Err = 0) Then UpdateFilters = true
End Function

Function GetItem(sItemGuid, oItem)
	On Error Resume Next
	GetItem = false
	
	Err.Clear
	Set oItem = m_ItemManagement.GetItemByGuid("{" & sItemGuid & "}")
	If ((Err = 0) AND (NOT IsNothing(oItem))) Then GetItem = true
End Function

Function IsNothing(ByRef oObject)
	IsNothing = false
	If TypeName(oObject) = "Nothing" Then IsNothing = true
End Function

SOLUTION