RESTAPI: Generate uninstall tasks for all MSI applications on target computer - Windows
6/25/2015 1:36:10 PM
Description
This task will generate uninstall tasks for all of the MSIs on the target computer in the same site as this task is run from using the current console operator username and password and the REST API. This task uses secure parameters so the password is encrypted.
notexists files whose ( name ofitstartswith"RESTAPI_ImportedTasks_"AND name ofitas lowercase ends with".log"AND ( now - modification time ofit < 7*day ) ) of folder "__BESData\__Global\Logs"of parent folder of client
notexists files whose(name ofitstartswith"RESTAPI_ImportedTasks_"AND name ofitas lowercase ends with".log"AND (now - modification time ofit < 7*day) ) of folder "__BESData\__Global\Logs"of parent folder of client
// DEBUGGING: The following is for debugging // appendfile {parameter "RootServerURL"} // appendfile {parameter "currentSiteName"} // appendfile {parameter "currentSiteType"} // appendfile {parameter "currentConsoleUser"} // move __appendfile __Download\parameters.txt // parameter "secret" of action
// -- START:DOWNLOADS -------------------------
// - This is the commandline 7zip console which is use to unpack installers // - https://www.virustotal.com/en/file/2a3afe19c180f8373fa02ff00254d5394fec0349f5804e0ad2f6067854ff28ac/analysis prefetch 7za.zip sha1:9ce9ce89ebc070fea5d679936f21f9dde25faae0 size:384846 http://iweb.dl.sourceforge.net/project/sevenzip/7-Zip/9.20/7za920.zip
// - This unzip is a compiled verion of unzip v5.52 fom http://info-zip.org/ // - https://www.virustotal.com/en/file/8d9b5190aace52a1db1ac73a65ee9999c329157c8e88f61a772433323d6b7a4a/analysis prefetch unzip.exe sha1:e1652b058195db3f5f754b7ab430652ae04a50b8 size:167936 http://software.bigfix.com/download/redist/unzip-5.52.exe
// Download CURL http://curl.haxx.se/download.html // - Analysis of the CURL.exe inside: https://www.virustotal.com/en/file/7e4379dc72cc25e8d546b3f4b4305b93b6521aaae47c1ea2ee49e4cc4ce8b033/analysis/ prefetch curl.cab sha1:1d104ff75f52718709307ba03af0fcad17c1237a size:1435991 http://skanthak.homepage.t-online.de/download/curl-7.43.0.cab
// EXTRACT using unzip: the 7zip command line utility waithidden __Download\unzip.exe -o "{pathname of file "7za.zip" of folder "__Download" of client folder of current site}" 7za.exe -d "{pathname of folder "__Download" of client folder of current site}"
// EXTRACT using 7zip: CURL waithidden"{ (pathname of file "7za.exe" of folder "__Download" of client folder of current site) }" e -i!I386\Curl.EXE -y -o"{pathname of folder "__Download" of client folder of current site}" "{pathname of file "curl.cab" of folder "__Download" of client folder of current site}"
// VERIFY: Make sure the parameters are set continueif{ (parameter "currentSiteName" as trimmed string != "") AND (parameter "currentSiteType" as trimmed string != "") AND (parameter "RootServerURL" as trimmed string != "") }
// REST API waithidden"{ (pathname of file "Curl.EXE" of folder "__Download" of client folder of current site) }" -k -o "{pathname of folder "__Download" of client folder of current site}\Tasks_{parameter "currentSiteName"}.xml" --user {parameter "currentConsoleUser"}:{parameter "secret"} https://{parameter "RootServerURL"}/api/tasks/{parameter "currentSiteType"}/{parameter "currentSiteName"}
// query system for all MSIs not already in existing uninstall tasks & generate uninstall tasks delete __createfile delete UninstallMSI_Tasks.bes
// CREATEFILE createfileuntil END_OF_FILE ="1.0" encoding="UTF-8"?> ="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BES.xsd"> { /* Generate MSI Uninstall Tasks */ ( (" Uninstall: MSI - " & it & " - WindowsThis task will uninstall the MSI: " & it & "
This task was automatically generated using the task: %22RESTAPI: Generate uninstall tasks for all MSI applications on target computer - Windows%22
%5d%5d>/* Windows Only */ windows of operating system= %225.1%22%5d%5d>/* Only run if " & it & " is installed */ exists keys whose( (exists values %22DisplayName%22 whose(it as string as lowercase starts with %22" & it & "%22 as lowercase) of it) AND (exists values whose(it as string as lowercase starts with %22msiexec%22) of it) ) of keys %22HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall%22 of ( x64 registries; x32 registries )Software Sharing0jgstew" & ( ((year of it as string &"-"& month of it as two digits &"-"& day_of_month of it as two digits) of date (local time zone) of it) of now ) & "x-fixlet-modification-time" & (now as string) & "BESCClick here to uninstall " & it & "waithidden msiexec.exe /X %7b name of keys whose( (exists values %22DisplayName%22 whose(it as string as lowercase starts with %22" & it & "%22 as lowercase) of it) AND (exists values whose(it as string as lowercase starts with %22msiexec%22) of it) ) of keys %22HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall%22 of ( x64 registries; x32 registries ) %7d /qn") of ( ( (if (it contains "%a9") then (preceding text of first "%a9" of it) else it) of (if (it contains "™") then (preceding text of first "™" of it) else it) of (if (it contains "%ae") then (preceding text of first "%ae" of it) else it) of unique values of (it as string) of values "DisplayName" of keys whose(exists values whose(it as string as lowercase starts with "msiexec") of it) of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of ( registry; (if (x64 of operating system) then (x64 registry) else NOTHING ) ) ) whose ( not exists (it, ( (preceding text of last " - Windows" of following text of first "Uninstall: MSI - " of it) of node values whose(it starts with "Uninstall: MSI - " AND it contains " - Windows") of xpaths "/BESAPI/Task/Name/text()" of xml documents of files whose( (name of it as lowercase ends with ".xml") AND (exists lines whose(it as lowercase starts with "
// Import UninstallMSI_Tasks.bes into custom site using API if there is at least one task inside (use secure parameter for user password) if{ (exists files "UninstallMSI_Tasks.bes" whose(exists contents whose(it contains "") of it) of folder "__Download" of client folder of current site) } // IMPORT waithidden"{ (pathname of file "Curl.EXE" of folder "__Download" of client folder of current site) }" -k -X POST -d @"{pathname of file "UninstallMSI_Tasks.bes" whose(exists contents whose(it contains "") of it) of folder "__Download" of client folder of current site}" --header "Content-Type:text/xml" -o "{(pathname of folder "__BESData\__Global\Logs" of parent folder of client)}\RESTAPI_ImportedTasks_{parameter "currentSiteName"}.log" --user {parameter "currentConsoleUser"}:{parameter "secret"} https://{parameter "RootServerURL"}/api/tasks/{parameter "currentSiteType"}/{parameter "currentSiteName"} endif
// VERIFY: Check if tasks were actually imported // TODO: Need to add a check to see if the log file was created after the action started running (See adobe CC template for an example) continueif{exists files whose((name of it = ("RESTAPI_ImportedTasks_" & (parameter "currentSiteName") & ".log")) AND exists lines whose(it contains "") of it) of folder "__BESData\__Global\Logs" of parent folder of client}
// NOT BEING USED:
// query custom site for all existing uninstall tasks // starts with "Uninstall: MSI - " // https://github.com/bigfix/restapi-examples/tree/master/evaluate-relevance/cURL // curl --data-urlencode "relevance=RELEVANCE" --user username:password https://server:port/api/query // (preceding text of last " - Windows" of following text of first "Uninstall: MSI - " of it) of names of custom bes fixlets whose( (name of it starts with "Uninstall: MSI - ") AND (name of it contains " - Windows") AND (source of it = "Configuration: Generate uninstall tasks for all MSI applications on target computer - Windows") ) // (preceding%20text%20of%20last%20%22%20-%20Windows%22%20of%20following%20text%20of%20first%20%22Uninstall%3A%20MSI%20-%20%22%20of%20it)%20of%20names%20of%20custom%20bes%20fixlets%20whose(%20(name%20of%20it%20starts%20with%20%22Uninstall%3A%20MSI%20-%20%22)%20AND%20(name%20of%20it%20contains%20%22%20-%20Windows%22)%20AND%20(source%20of%20it%20%3D%20%22Configuration%3A%20Generate%20uninstall%20tasks%20for%20all%20MSI%20applications%20on%20target%20computer%20-%20Windows%22)%20)
Success Criteria
This action will be considered successful when the applicability relevance evaluates to false.
Action 2
Action Link Click
here to review this task in the bigfix.me Content Database.
Seems to be working for me. Should match this: https://www.virustotal.com/en/file/56bb84b3671b21fd41d497d88fba6cad72937312697423fa0fe7a3f1a37e0ad1/analysis/1439081379/