Migrating software to new workstations (Altiris NS)

The web-interface of Altiris Notification Server can sometimes be a bit sluggish.
Certainly if you have to add a computer to 10 or more collections.
To speed things a bit up I have written this Powershell script, which uses the Altiris ASDK to perform queries to Altiris NS.
This script was intended to ensure that a new workstation receives the same software as the old workstation.
It also can be used to just clone the software of a workstation to a new workstation.

#Active Directory Domain
$domain = "LCODE"
#Host name of Altiris Notification Server
$nsserver = "ALTIRISNS"
#Major resource collection
$maincollection = "LCODE Software Collections"
#Sub resource collection
$softinstallcollection = "Software Installation"

#This is a schematic of the structure maintained in Notification Server
#The major resource collection is a child of Software Management
#The name of the sub resource collection is just the first part of the full name (Software Installation)
# as this is being matched with the children of the major resource collection
# all children beginning with that name are being enumerated
# eg. "Software Installation" causes "Software Installation 1" and "Software Installation 2" to be enumerated
#
#Resources tab
# Resource Management
#  [-]  Collections
#       [-]  Software Management
#            [-]  LCODE Software Collections
#         [-]  Software Installation 1
#             []  SW Package 1
#             []  SW Package 2
#         [-]  Software Installation 2
#             []  SW Package 3
#             []  SW Package 4
#

#Load Altiris ASDK
$coll = New-Object -comObject Altiris.ASDK.NS.CollectionManagement
$item = New-Object -comObject Altiris.ASDk.NS.ItemManagement
$res = New-Object -comObject Altiris.ASDK.NS.ResourceManagement
$report = New-Object -comObject Altiris.ASDK.NS.ReportManagement

#Establish connections to Altiris Notification Server
$report.targetserver = $nsserver
$report.authenticate()
$item.targetserver = $nsserver
$item.authenticate()
$coll.targetserver = $nsserver
$coll.authenticate()
$res.targetserver = $nsserver
$res.authenticate()

#Retrieve GUID of the Major resource collection
$maincollectionguid = ($item.getItemsByName($maincollection)).GetValue(0).Guid

#Ask user to enter hostnames of old and new pc
$oldpc = Read-Host "Old PC"
$newpc = Read-Host "New PC"

#Retrieve GUIDs of computers
$oldpcguid = $res.getComputerByNameAndDomain($oldpc,$domain)
$newpcguid = $res.getComputerByNameAndDomain($newpc,$domain)

#Check if we don't have an empty GUID for one of the computers
if(($oldpcguid.length -gt 0) -and ($newpcguid.length -gt 0)){

#Retrieve all software collections
$softwarecoll = $item.GetItemsInFolder($maincollectionguid) | foreach-object -process { $item.GetItemsInFolder($_.Guid) | where-object { $_.parentfoldername -match $softinstallcollection } }

#Enumerate all software collections
$softwarecoll | foreach-object -process{
$softguid = $_.guid

#Check if OldPC is in software collection
$result = $coll.getinclusions($softguid,"Resource") | where-object { $_.name -eq $oldpc}
if($result -ne $null){
$softname = $_.Name

#Display and log that OldPC has this piece of software
Write-Host "$oldpc $softname"
Add-Content ".\$newpc.txt" -value "$oldpc $softname"

#Add NewPC to software collection
$coll.addinclusions($softguid,$newpcguid)

#Check if NewPC is in software collection
$result = $coll.getinclusions($softguid,"Resource") | where-object { $_.name -eq $newpc}
if($result -ne $null){

#Display and log that NewPC has this piece of software
Write-Host "$newpc $softname"
Add-Content ".\$newpc.txt" -value "$newpc $softname"
}

#Refresh the software collection
$coll.updatecollections($softguid)
}
#Write-Host "Result:$result"
}
}else{

#One of the GUIDs could not be found. Most likely computername is wrong or it does not exist in Notification Server
Write-Host "Problem finding GUID for Old/New PC"
Write-Host "Old PC: $oldpcguid"
Write-Host "New PC: $newpcguid"
}
 

Tags: , , , , ,

Leave a Reply

You must be logged in to post a comment.