In NS 7.5 we use filters with static inclusions to deploy specific pieces of licensed software. While this process works well, it presents a challenge when an asset goes from Active to In stock. Ideally when an asset is marked as in stock we would want to go in and remove it from the filters it was set to be statically included in. The idea behind this is that we wouldn't want the same licensed software to be deployed to the next computer when it was reimaged.
For us, only our asset manager can remove computers from filters. For computers that have only a couple of filters this isn't a problem. For other computers there are many filters that need to have the inclusion removed. This can lead to be a very time consuming process. The only other option we had was to delete the asset and let it repopulate. This obviously worked, but lead us to loose all of the asset history and we didn.want to do that.
As a process improvement we have given the rest of IT the ability to mark assets as In stock, Retired, or Disposed for their location. By giving them this access it has allowed more timely updates of assets. That being said it didn't handle removing them from the filters. To address this I started looking on connect. I found a few articles about people using the asdk to do management tasks like this. I then found a script that had the basis of doing this too. I worked through the script with the documentation installed with the asdk to figure out what it was doing and made several modifications.
Option Explicit
dim itemmanagement
Dim oCollectionManagement, oItemManagement
Dim itemComputer, allItemNames, NSItemDetails, folders()
Const FILTERFOLDER = "{5fe3c58c-176f-4d50-9797-cf986f81487a}" ' FolderGUID to start searching under
set oitemManagement = CreateObject("Altiris.ASDK.NS.ItemManagement")
Set oCollectionManagement = CreateObject("Altiris.ASDK.NS.CollectionManagement")
oitemManagement.Protocol = "HTTPS"
oitemManagement.Port = "443"
oItemManagement.TargetServer = "smp"'this had to match the ssl cert
oItemManagement.Authenticate()
oCollectionManagement.Protocol = "HTTPS"
oCollectionManagement.Port = "443"
oCollectionManagement.TargetServer = "smp"'again had to match ssl cert name
oCollectionManagement.Authenticate()
itemComputer = "%!ItemGuid!%"
' recursive function going through all Folders and Filters below
Function recurseCheck(GUID)
for each NSItemDetails in oItemManagement.GetItemsInFolder(GUID)
If NSItemDetails.TypeName = "PresentationFolder" Then
recurseCheck(NSItemDetails.Guid)
Else
Call oCollectionManagement.RemoveInclusions(NSItemDetails.Guid, itemComputer)
Call oCollectionManagement.UpdateCollections(NSItemDetails.Guid)
End If
next
End Function
recurseCheck(FILTERFOLDER)
wscript.sleep 1000
For this I created a script that ran against Notificatoin Server. It looks for filters under a specific folder, it then tries to remove the computer from each of the filters it finds under the sub folders. This script is also set to use SSL. the important part was that the hostname of the NS had to match the hostname of the SSL Certificate on the NS itself. The script takes an item guid as input I then created a very simple report that looks like the following
select ParentResourceGuid as ItemGuid from ResourceAssociation
where ResourceAssociationTypeGuid = '3028166F-C0D6-41D8-9CB7-F64852E0FD01' -- status resourceassociation
and ChildResourceGuid in ('1C139F6C-F210-4002-90D0-4DFAF98D5FA4','492C463B-AFA2-4DD6-AE73-6FD2C7B0E489','485C2F89-2FAF-46F3-9E98-D80116D1022D') -- in stock, retired, disposed statuses
and CreatedDate between CURRENT_TIMESTAMP -1 and CURRENT_TIMESTAMP
This looks for computers that have been set as in stock, retired, or disposed in the last 24 hours.
Finally, to tie it all together I then created an automation policy to run daily. It runs once for each row in the report. The itemguid from this report gets mapped into the job under the parameters section and passes each one through to the script.
I hope this helps someone else who has many filter inclusions to clean up as assets change status.