Am new with using Bigfix and updating XML files. Do you have a good method or can Bigfix run a command to update the attributes and nodes within an XML file?
This is an example of the xml file that am trying update. Right now, the only way that I was able to run updates is by using a powershell script.
Here’s an example of one I did recently to update the xml for a scheduled task, that prompts for some data before running the task using action parameter query.
action parameter query "StartBoundary" with Description "Start Hour(s):"
action parameter query "StartMinutes" with Description "Start Min(s):"
action parameter query "EndBoundary" with Description "End Hour(s):"
action parameter query "EndMinutes" with Description "End Min(s):"
delete c:\Temp\update_xml.ps1
delete __createfile
createfile until EOF
$new_StartBoundary = [DateTime]::Today.AddDays(0).AddHours({parameter "StartBoundary" of action}).AddMinutes({parameter "StartMinutes" of action}) # Sets it todays date at 5pm [e.g. Thursday, February 14, 2019 5:00:00 PM]
$new_StartBoundary = $new_StartBoundary.ToString("yyyy-MM-dd'T'HH:mm:ss")
$new_EndBoundary = [DateTime]::Today.AddDays(1).AddHours({parameter "EndBoundary" of action}).AddMinutes({parameter "EndMinutes" of action}) # Sets it tomorrows date at 6am [e.g. Friday, February 15, 2019 6:00:00 AM]
$new_EndBoundary = $new_EndBoundary.ToString("yyyy-MM-dd'T'HH:mm:ss")
[xml]$TaskXML = Get-Content "C:\Temp\EODReboot.xml" # Get the xml file
$TaskXML.Task.Triggers.TimeTrigger.StartBoundary = $new_StartBoundary # update the StartBoundary node with new_StartBoundary
$TaskXML.Task.Triggers.TimeTrigger.EndBoundary = $new_EndBoundary # update the EndBoundary node with new_EndBoundary
$TaskXML.Save("C:\Temp\EODReboot.xml") # save the file with updates
EOF
copy __createfile c:\Temp\update_xml.ps1
runhidden cmd /K powershell.exe -ExecutionPolicy Bypass c:\Temp\update_xml.ps1
I have noticed that when no information is answered to one of the action parameter, the script will update the xml attributes that needs to be updated; but,it is erasing information for other attributes. it is like I cannot update just one attribute at the time but all them.
$XMLFile.Inventory.PrimaryUser.FirstName="{if (parameter “FirstName”) != “” then (parameter “FirstName”) else (node values of child nodes of selects “//Inventory/PrimaryUser/FirstName” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.PrimaryUser.LastName="{if (parameter “LastName”) != “” then (parameter “LastName”) else (node values of child nodes of selects “//Inventory/PrimaryUser/LastName” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.PrimaryUser.Username="{if (parameter “Username”) != “” then (parameter “Username”) else (node values of child nodes of selects “//Inventory/PrimaryUser/Username” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.PrimaryUser.PrimaryRole="{if (parameter “PrimaryRole”) != “” then (parameter “PrimaryRole”) else (node values of child nodes of selects “//Inventory/PrimaryUser/PrimaryRole” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Ownership.Organization="{parameter “Organization”}"
$XMLFile.Inventory.Ownership.Division="{if (parameter “Division”) != “” then (parameter “Division”) else (node values of child nodes of selects “//Inventory/PrimaryUser/Division” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Ownership.Subdivision="{if (parameter “Subdivision”) != “” then (parameter “Subdivision”) else (node values of child nodes of selects “//Inventory/PrimaryUser/Subdivision” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Ownership.Group="{if (parameter “Group”) != “” then (parameter “Group”) else (node values of child nodes of selects “//Inventory/PrimaryUser/Group” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Ownership.BudgetID="{if (parameter “BudgetID”) != “” then (parameter “BudgetID”) else (node values of child nodes of selects “//Inventory/PrimaryUser/BudgetID” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Ownership.FY="{if (parameter “FY”) != “” then (parameter “FY”) else (node values of child nodes of selects “//Inventory/PrimaryUser/FY” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Ownership.PurchaseDate="{if (parameter “PurchaseDate”) != “” then (parameter “PurchaseDate”) else (node values of child nodes of selects “//Inventory/PrimaryUser/PurchaseDate” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Ownership.LifeCycleDate="{if (parameter “LifeCycleDate”) != “” then (parameter “LifeCycleDate”) else (node values of child nodes of selects “//Inventory/PrimaryUser/LifeCycleDate” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Ownership.OriginalRequestID="{if (parameter “OriginalRequestID”) != “” then (parameter “OriginalRequestID”) else (node values of child nodes of selects “//Inventory/PrimaryUser/OriginalRequestID” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Location.Campus="{if (parameter “Corporate”) != “” then (parameter “Corporate”) else (node values of child nodes of selects “//Inventory/PrimaryUser/Corporate” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Location.Building="{if (parameter “Building”) != “” then (parameter “Building”) else (node values of child nodes of selects “//Inventory/PrimaryUser/Building” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Location.Room="{if (parameter “Room”) != “” then (parameter “Room”) else (node values of child nodes of selects “//Inventory/PrimaryUser/Room” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Location.Address.Street="{if (parameter “Street”) != “” then (parameter “Street”) else (node values of child nodes of selects “//Inventory/PrimaryUser/Street” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Location.Address.City="{if (parameter “City”) != “” then (parameter “City”) else (node values of child nodes of selects “//Inventory/PrimaryUser/City” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Location.Address.State="{if (parameter “State”) != “” then (parameter “State”) else (node values of child nodes of selects “//Inventory/PrimaryUser/State” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.Inventory.Location.Address.ZipCode="{if (parameter “ZipCode”) != “” then (parameter “ZipCode”) else (node values of child nodes of selects “//Inventory/PrimaryUser/ZipCode” of xml documents of files “machine\info\Inventory.xml” of windows folder)}"
$XMLFile.save(“C:\Windows\machine\info\Inventory.xml”)
EOF
// Run powershell script changes execution policy just for this file from this task
waithidden cmd.exe /C powershell.exe -executionpolicy bypass -file “{(pathname of client folder of current site) & “\Inventory.ps1”}”
I mocked up the first three items you had (FirstName, LastName, and UserName) in the fixletdebugger and I’m able to update the xml correctly even when I leave a parameter blank. I did write it a bit differntly than you, but it works correctly.
parameter "FirstName"=""
parameter "LastName"=""
parameter "UserName"="User1234"
delete c:\windows\Temp\update_xml.ps1
delete __createfile
createfile until EOF
# Get the xml file
[xml]$TaskXML = Get-Content "C:\Temp\inventory\inventory.xml"
# if the parameter FirstName is not blank set PrimaryUser.FirstName to the value of the parameter FirstName
# else if the paramater FirstName is blank set PrimaryUser.FirstName to the current value of PrimaryUser.FirstName in the xml
if ("{parameter "FirstName"}"){{
$TaskXML.Inventory.PrimaryUser.FirstName = "{parameter "FirstName"}"
}else {{
$TaskXML.Inventory.PrimaryUser.FirstName = $TaskXML.Inventory.PrimaryUser.FirstName
}
# if the parameter LastName is not blank set PrimaryUser.LastName to the value of the parameter LastName
# else if the paramater LastName is blank set PrimaryUser.LastName to the current value of PrimaryUser.LastName in the xml
if ("{parameter "LastName"}"){{
$TaskXML.Inventory.PrimaryUser.LastName = "{parameter "LastName"}"
}else {{
$TaskXML.Inventory.PrimaryUser.LastName = $TaskXML.Inventory.PrimaryUser.LastName
}
# if the parameter UserName is not blank set PrimaryUser.UserName to the value of the parameter UserName
# else if the paramater UserName is blank set PrimaryUser.UserName to the current value of PrimaryUser.UserName in the xml
if ("{parameter "UserName"}"){{
$TaskXML.Inventory.PrimaryUser.Username = "{parameter "UserName"}"
}else{{
$TaskXML.Inventory.PrimaryUser.Username = $TaskXML.Inventory.PrimaryUser.Username
}
# Save the xml file
$TaskXML.Save("C:\Temp\inventory\inventory.xml")
EOF
copy __createfile c:\windows\temp\update_xml.ps1
runhidden cmd /K powershell.exe -ExecutionPolicy Bypass c:\windows\Temp\update_xml.ps1