In this article, we're going to automate A to B software migrations using the ASDK, NS Reports, NS SQL Tables and DS Jobs. When we're finished, dropping one job on the New machine will automatically install all defined software that existed on the OLD machine.
Let's Get started:
1) Installing the ASDK
You will need the following ASDK Components installed on the NS and DS servers:
- Altiris_ASDK_NS_COM.msi
- Altiris_ASDK_DS_COM.msi
- Altiris_ASDK_NS_Server.msi
- Altiris_ASDK_DS_Server.msi
2) Prepare the Reference Machine
In order to report on all software that is installed on the OLD machine, It is probably a good idea to have all software included within your Gold Image stored in a SQL table which we can then use as an exclusion within the report. This will help keep the results of the report smaller as it will return fewer rows, plus the client will be receiving this software during imaging.
Step 1) Find a reference PC and image the machine using your production GOLD Image. Make sure that no other software is installed other than what is already included within the image.
Step 2) On the NS Server, go to the Resources Tab and browse to Collections -> New -> Collection:
Create a new collection called "Gold Image Software Inventory". At this time, do not add any resources to this collection.
Step 3) Go to the Tasks Tab and browse to Assets and Inventory -> Inventory -> Windows -> Inventory Tasks -> Software Inventory. Right click and select clone.
Rename the task "Gold Inventory Capture" and apply it to the "Gold Image Software Inventory" collection we created earlier. Enable the task then click "Apply".
Step 4) On the Reference machine, install the NS Agent. Make sure that no NS policy is applied to this machine. Once the agent is installed and has checked into the NS Server, add the reference machine as an explicit inclusion to the "Gold Image Software Inventory" collection created earlier.
Use the NS Agent Properties to verify that the "Gold Inventory Capture" task has run. Once finished, we now have software data captured and we'll now need to create a static SQL table referencing this data.
3) Create a static SQL table to store the captured Gold Image Software
Step 1) On the NS Server, go to the Resources tab and browse to the "Gold Image Software Inventory" collection. Right click on your reference machine and select properties. Copy the Guid for the reference machine. In this case it"s "a7a3ec25-f4ca-46ce-b662-2bb5a9acdc46".
Step 2) Open Microsoft SQL Server Management Studio and run the following query:
****** CODE START ******
CREATE TABLE [GOLD IMAGE SOFTWARE]
(
[Manufacturer][nvarchar] (255),
[ProductName][nvarchar] (255),
[ProductVersion][nvarchar] (255),
[Language][nvarchar] (255),
[File Name][nvarchar] (255),
[File Size][nvarchar] (255),
[Directory File Time] [datetime],
[Executable Type][nvarchar] (255),
[InternalName][nvarchar] (255),
[KnownAs][nvarchar] (255),
[File Description][nvarchar] (255),
[File Path][nvarchar] (255),
[File Extension][nvarchar] (255),
[File Modification Time] [datetime]
)
insert into [GOLD IMAGE SOFTWARE]
(
[Manufacturer],
[ProductName],
[ProductVersion],
[Language],
[File Name],
[File Size],
[Directory File Time],
[Executable Type],
[InternalName],
[KnownAs],
[File Description],
[File Path],
[File Extension],
[File Modification Time]
)
SELECT
[Manufacturer],
[ProductName],
[ProductVersion],
[Language],
[File Name],
[File Size],
[Directory File Time],
[Executable Type],
[InternalName],
[KnownAs],
[File Description],
[File Path],
[File Extension],
[File Modification Time]
FROM inv_aex_sw_audit_software
-- The following line is the GUID OF YOUR REFERENCE MACHINE
WHERE _ResourceGuid = 'A7A3EC25-F4CA-46CE-B662-2BB5A9ACDC46'
***** CODE END *****
A Static table called "GOLD IMAGE SOFTWARE " has now been created.
4) Create your "Distribute Software" jobs within deployment server
If you haven't already done so, you will need to create a "Distribute Software" job for all approved software packages within your environment. The "Deliver Software" jobs should be set up to run silently and without user interaction. (This process is beyond the scope of this document, however information regarding this process can be found in the Deployment Server Documentation).
**This above step is important as we will need the DS Job ID before progressing to the next step**
5) Getting the DS JOB ID
Run the following SQL query in Microsoft SQL Studio Management Studio against the deployment server database:
***** CODE START *****
select DISTINCT event_id AS JobID, install_file from dbo.install_task
***** CODE END *****
(You may also want to create a permanent report using the above script in the NS server for future reference)
You now have a reference to the DS Distribute Software Job and the DS JOB ID
6) Creating the Migration Report
In this section we will create a report which will be used by the ASDK to schedule DS software installation jobs.
Step 1) Take the following SQL Query and modify the "CASE" Statement (commented below):
***** CODE START *****
select
vc.Name,
sw.Manufacturer,
sw.ProductName,
sw.ProductVersion,
sw.[File Name],
sw.[File Size],
sw.[File Path],
sw.ProductName + ' | ' + sw.[File name] + ' | ' + sw.[ProductVersion] as [Installed Software],
-- BELOW IS WHERE YOU WANT TO REFERENCE ALL YOUR DS JOB ID"s AND SOFTWARE FILES THAT WILL
-- NEED TO BE MIGRATED USING THE QUERY/REPORT CREATED EARLIER.
-- TWO EXAMPLES ARE SHOWN HERE
'ID' = CASE
WHEN sw.[File Name] = 'winamp.exe' AND sw.productversion like '%' THEN '2000353'
WHEN sw.[File Name] = 'winzip32.exe' AND sw.productversion like '%' THEN '2000165'
ELSE
'NO JOB ID'
END
from vcomputer vc
join Inv_Aex_SW_Audit_Software sw
on vc.guid = sw.[_ResourceGuid]
where sw.[_ResourceGuid] = '%Computer_Guid%'
and sw.ProductName + ' | ' + [File name] + ' | ' + sw.[ProductVersion] not in (
select sw.ProductName + ' | ' + [File name] + ' | ' + sw.[ProductVersion]
from [GOLD IMAGE SOFTWARE])
***** CODE END *****
Step 2) On the NS Server go to the Reports Tab. Right click on reports and select NEW -> Report
Name the Report "Migration Report" and choose " Enter SQL Directly". Paste the modified query (above) into the SQL Statement box.
*NOTE: When adding software applications and DS JOB IDs, all that needs to be done is editing this report and reflecting changes within the "CASE" Statement.
Step 3) You"ll notice that we are using the token "%Computer_Guid%" in the sql query used in the report. We must now add a parameter to match that token.
Edit the report, "Migration Report" and click on "New Parameter". In the "Name” field enter Computer_Guid, Keep the parameter type "Basic", check the "Prompt user for value when report is run and type the value of "%" into the Value field.
Click OK, then click Apply.
Your report is now ready to use with the ASDK
7) Modify the VB Script
STEP 1) Copy the following code into a text editor and modify the following (in bold):
**NOTE - If your NS and DS Servers are on different boxes, you may need to add additional authentication to your Object management within the script. See the ASDK samples for reference.
***** CODE START *****
'----------------------------------------------------------------------------
'| Script created by Mike English and John Golembiewski
'| ITS Partners LLC
'| http://www.itsdelivers.com
'|
'----------------------------------------------------------------------------
Dim X, sOldpc, sNewpc
Dim sNSServer
Dim sDSServer
'MODIFY THE VALUES BELOW TO SUIT YOUR NS AND DS SERVERS
sNSServer = "ALLTIRIS"
sDSServer = "ALLTIRIS"
'Add ASDK NS Resource Object
set resourceManagement = CreateObject("Altiris.ASDK.NS.ResourceManagement")
resourceManagement.TargetServer = sNSServer
resourceManagement.Authenticate()
Set reportManagement = CreateObject("Altiris.ASDK.NS.ReportManagement")
reportManagement.TargetServer = sNSServer
reportManagement.Authenticate()
dowork()
scriptBailOut2()
Sub dowork()
Set oArgs = WScript.Arguments
If oArgs.count = 2 then
sNewpc = WScript.Arguments(0)
sOldpc = WScript.Arguments(1)
wscript.Echo "********************************************"
Wscript.Echo " Script Start Time = " & Now()
wscript.Echo "********************************************"
WScript.Echo " 0) New Computer Name = " + sNewpc
WScript.Echo " 1) Old Computer Name = " + sOldpc
Else
wscript.Echo "********************************************"
wscript.Echo ""
WScript.Echo ""
WScript.Echo "ERROR: This script requires two variables passed, OLD PC
NAME, NEW PC NAME."
wscript.Echo " Example for calling script... cscript
DS_a2bmigration.vbs ALLTIRIS XPCLEAN"
wscript.Echo ""
wscript.Echo "********************************************"
scriptBailOut2
End If
oldguid = resourceManagement.GetResourceByName(sOldpc, "Computer")
WScript.Echo " 2) Applications Existing on OLDPC : " + sOldpc
'PUT THE "MIGRATION REPORT" GUID HERE
reportGuid ="a2edfbb8-9a20-40bf-b816-0c3570e3372d"
params = "Computer_Guid=" & oldguid
Set results = reportManagement.RunReportWithParameters(reportGuid, params)
intcounter = 1
Do While Not results.eof
sProduct = results.Fields.Item("ProductName").Value
sJobID = results.Fields.Item("ID").Value
WScript.Echo " " & intcounter & ") " & sProduct & vbCrLf & " "
& vbCrLf & " DS Job ID: " & sJobID
results.MoveNext()
intcounter = intcounter + 1
If sJobID <> "NO JOB ID" Then
'WScript.Echo " " & sJobID
'Add new machine to ds job
WScript.Echo " >> Assigning DS Jobs: " & sNewpc & " for " &
sProduct
'create shell object to execute commands
Set oShell = WScript.CreateObject ("WSCript.shell")
sTime = """2009-01-01 00:00"""
oShell.Run("\\" & sDSSERVER & "\eXpress\axSched.exe " & sNewpc &
" -jid " & sJobID & " /t " & sTime)
End If
wscript.Echo " ********************************************"
loop
If intcounter > 1 Then
wscript.Echo "********************************************"
wscript.Echo "End of Software Migration Installation from " & sOldpc & "
to " & sNewpc
wscript.Echo "********************************************"
scriptBailOut2
End If
End Sub
Sub scriptBailOut2()
Set reportManagement = Nothing
WScript.Quit()
End Sub
***** CODE END *****
Step 2) Create a directory in the root of the eXpress share and call it, "A2BMIGRATION". Save the vbs file as "DS_a2bmigration.vbs" and place into this directory.
8) Creating the DS Job
Step 1) Create a DS Job called "A2B Migration". Add a "Run Script Task" and paste the following into the script window:
***** CODE START *****
c:
cd \Program Files\Altiris\eXpress\Deployment Server\A2BMIGRATION
cscript DS_a2bmigration.vbs "%COMPNAME%" "%#!location@phone%" > %COMPNAME%.txt
***** CODE END *****
Click next.
Select "Run the script locally on the Deployment Server"
Select "Run when the agent is connected
Click Next
Click Finish
9) Preparing the NEW Machine
Step 1) In the DS console, right click on the new machine and select "PROPERTIES"
Step 2) Click "LOCATION" and enter the clients OLD hostname into the PHONE field:
Step 3) Click OK to finish
The machine is now ready to run the Job.
10) Running the Migration Job (Summary)
Before successfully running the DS Migration job, the following must be in place
- The Old machine must already exist in the Reporting NS"s Database
a. Software inventory data must exist for the machine
- A Deployment Server Job must be created for every executable that is returned from the Migration Report
a. A DS job must be created for every specific executable / version of existing software that you want to be migrated over. These jobs can bereused, and can be scheduled against other clients needing the same software installed.
b. The DS JOB ID and executable must be defined in the migration report
- The clients OLD machine name must be populated in the phone field of the machines properties within the DS Console.
That's it. Happy Migrating