API: Locate GUID for package to use InstallUpdate command in "Issue a Command to a Device"

  • 26 October 2020
  • 0 replies
  • 50 views

Userlevel 5

If trying to use the InstallUpdate command to “Issue a Command to a Device”, you’ll see that it wants a GUID for the update:

https://docs.automox.com/api/endpoints/issue-a-command-to-a-device


So that you don’t have to comb through the registry trying to find it, you can run this script on a device that has the update installed to find the GUID so that you can use it to install it on other devices with API:


$UninstallKeys = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
$null = New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS
$UninstallKeys += Get-ChildItem HKU: -ErrorAction SilentlyContinue | Where-Object { $_.Name -match 'S-\d-\d+-(\d+-){1,14}\d+$' } | ForEach-Object { "HKU:\$($_.PSChildName)\Software\Microsoft\Windows\CurrentVersion\Uninstall" }

if (-not $UninstallKeys) {
Write-Verbose -Message 'No software registry keys found'
} else {
foreach ($UninstallKey in $UninstallKeys) {
#Get-ChildItem -Path $UninstallKey -ErrorAction SilentlyContinue | Where {$_.PSChildName -match '^{[A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}}$'} | Select-Object @{n='GUID';e={$_.PSChildName}}, @{n='Name'; e={$_.GetValue('DisplayName')}}
if ($PSBoundParameters.ContainsKey('Name')) {
$WhereBlock = { ($_.PSChildName -match '^{[A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}}$') -and ($_.GetValue('DisplayName') -like "$Name*") }
} else {
$WhereBlock = { ($_.PSChildName -match '^{[A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}}$') -and ($_.GetValue('DisplayName')) }
}
$gciParams = @{
Path = $UninstallKey
ErrorAction = 'SilentlyContinue'
}
$selectProperties = @(
@{n='GUID'; e={$_.PSChildName}},
@{n='Name'; e={$_.GetValue('DisplayName')}}
)
Get-ChildItem @gciParams | Where $WhereBlock | Select-Object -Property $selectProperties
}
}

Remove-PSDrive -Name HKU


0 replies

Be the first to reply!

Reply