RESTAPI: Generate uninstall tasks for all MSI applications on target computer - Windows
Log In or Register to download the BES file, and more.

0 Votes

Versioning - This is the latest version.

1RESTAPI: Generate uninstall tasks for all MSI applications on target computer - Windows10/9/2014 1:42:25 PM
2RESTAPI: Generate uninstall tasks for all MSI applications on target computer - Windows10/9/2014 1:45:24 PM
3RESTAPI: Generate uninstall tasks for all MSI applications on target computer - Windows10/9/2014 2:02:04 PM
4RESTAPI: Generate uninstall tasks for all MSI applications on target computer - Windows6/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.

 

References:

http://superuser.com/questions/149329/what-is-the-curl-command-line-syntax-to-do-a-post-request

https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/Tivoli%20Endpoint%20Manager/page/RESTAPI%20Task

https://github.com/bigfix/restapi-examples/tree/master/evaluate-relevance/cURL

 

Parameter Values:   (queried using JavaScript & console based session relevance)


Property Details

ID6092
StatusProduction - Fully Tested and Ready for Production
TitleRESTAPI: Generate uninstall tasks for all MSI applications on target computer - Windows
DomainBESC
CategoryConfiguration
Download Size0
Source IDjgstew
Source Release Date10/9/2014 12:00:00 AM
Added by on 6/25/2015 1:36:10 PM
Last Modified by on 6/25/2015 1:36:10 PM
Counters 14477 Views / 127 Downloads
User Rating 1 star 2 star 3 star 4 star 5 star * Average over 0 ratings. ** Log In or Register to add your rating.

Relevance

Windows Only (Relevance 2997197)
Used in 6452 fixlets and 32 analyses   * Results in a true/false
Show indented relevance
/* Windows Only */ windows of operating system
Used in 158 fixlets and 17 analyses   * Results in a true/false
Show indented relevance
/* Windows XP or Higher */ version of operating system >= "5.1"
BES Client is version 9+ (Relevance 2999387)
Used in 20 fixlets   * Results in a true/false
Show indented relevance
version of client >= "9.0" as version
Used in 5 fixlets   * Results in a true/false
Show indented relevance
not exists files whose(name of it starts with "RESTAPI_ImportedTasks_" AND name of it as lowercase ends with ".log" AND (now - modification time of it < 7*day) ) of folder "__BESData\__Global\Logs" of parent folder of client

Actions

Action 1 (default)

Action Link Click here to deploy this action.
Script Type BigFix Action Script
// 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

// -- END:DOWNLOADS ---------------------------


// ADD TO UTILITY CACHE: unzip,7zip,curl
utility __Download\unzip.exe
utility __Download\7za.zip
utility __Download\curl.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
continue if { (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
createfile until 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 Sharing0RESTAPI: Generate uninstall tasks for all MSI applications on target computer - Windowsjgstew" & ( ((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 "


END_OF_FILE

move __createfile __Download\UninstallMSI_Tasks.bes

// 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)
continue if{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.
Script Type URL
http://bigfix.me/cdb/fixlet/3876
    

Sharing

Social Media:
Share this page on Yammer

Comments

Log In or Register to leave comments!
byou -
Thanks.. I'll check your Github later
jgstew -
The javascript errors are probably due to BigFix.Me screwing up the file contents in some way. I'll have to post a copy on GitHub.
byou -
Using 9.5 getting javascript error "do you want to continue running this script" Yes or No answer result in console error
jgstew -
Hmm, I'll have to check. You should get a javascript notification about unsigned something, but when you accept that, you shouldn't get errors.
chadflorian -
Hey man... does this need some update to function on 9.5.2? Getting Javascript errors.
jgstew -
Seems to be working for me. Should match this: https://www.virustotal.com/en/file/56bb84b3671b21fd41d497d88fba6cad72937312697423fa0fe7a3f1a37e0ad1/analysis/1439081379/
Tim.Rice -
The CURL download URL is not working.
jgstew -
Fixed some issues.