Advertisement
nullzilla

Task - Dell Command Update

May 11th, 2021 (edited)
1,260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Import-Module $env:SyncroModule -DisableNameChecking
  2.  
  3. # Requires Chocolatey
  4. # Reboot disable switch doesn't seem to work 100%, so schedule after hours
  5. # Some code borrowed from https://www.cyberdrain.com/monitoring-with-powershell-monitoring-dell-driver-updates-dcu-3-1/
  6. # TODO:
  7. # failure catching
  8. # handling needed reboots
  9. # CLI Reference: https://www.dell.com/support/manuals/en-us/command-update/dellcommandupdate_rg/dell-command-|-update-cli-commands?guid=guid-92619086-5f7c-4a05-bce2-0d560c15e8ed&lang=en-us
  10.  
  11. $dcu = "${env:ProgramFiles(x86)}\Dell\CommandUpdate"
  12. $choco = "$env:allusersprofile\chocolatey\choco.exe"
  13. $homepath = 'c:\yourpath'
  14.  
  15. if (-not (Test-Path "$homepath")) { mkdir "$homepath" | Out-Null }
  16. if ((Get-CimInstance -ClassName Win32_ComputerSystem).Manufacturer -notlike 'Dell*') {
  17.     Write-Host "System Manufacturer is not Dell, exiting"
  18.     exit 0
  19. }
  20. $model = (Get-CimInstance -ClassName Win32_ComputerSystem).Model
  21. if ($model -notlike '*OptiPlex*' -and $model -notlike '*Latitude*' -and $model -notlike '*Precision*' -and $model -notlike '*Venue*' -and $model -notlike '*XPS*'){
  22.     Write-Host "Model not supported, installing Dell Update instead and exiting"
  23.     &$choco upgrade dell-update -y --no-progress
  24.     exit 0
  25. }
  26.  
  27. # Uninstall Existing Dell Update Apps
  28. $appstoremove = @(
  29. "Dell Command | Update for Windows 10"
  30. "Dell SupportAssist"
  31. "Dell SupportAssist Remediation"
  32. )
  33. function Get-InstalledSoftware {
  34.     Param (
  35.         [string]$ApplicationName
  36.     )
  37.     $32BitPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
  38.     $64BitPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*"
  39.     # Empty array to store applications
  40.     $Apps = @()
  41.     # Retreive globally installed applications
  42.     $Apps += Get-ItemProperty "Registry::HKEY_LOCAL_MACHINE\$32BitPath"
  43.     $Apps += Get-ItemProperty "Registry::HKEY_LOCAL_MACHINE\$64BitPath"
  44.     $returnVal = @()
  45.     foreach ($app in $Apps) {
  46.       if ($app.DisplayName -like "*$ApplicationName*") {
  47.         $returnVal += $app
  48.       }
  49.     }
  50.     return $returnVal
  51. }
  52. $executable = $env:windir + "\system32\msiexec.exe"
  53. foreach ($app in $appstoremove) {
  54.     Get-InstalledSoftware | Where-Object { $_.DisplayName -like "*$app*" -and $_.UninstallString -like "*MsiExec.exe*" } | Foreach-Object {
  55.         Write-Host "Uninstalling $($_.DisplayName)..." -NoNewline
  56.         $parameters = "/x " + $_.PSChildName + [char]32 + "/qn REBOOT=ReallySupress /norestart"
  57.         $errCode = (Start-Process -FilePath $executable -ArgumentList $parameters -Wait -Passthru).ExitCode
  58.         If (($errCode -eq 0) -or ($errCode -eq 3010) -or ($errCode -eq 1605)) {
  59.             Write-Host " Success" -ForegroundColor Green
  60.         } else {
  61.             Write-Host " Failed with error code"$errCode -ForegroundColor Red
  62.         }
  63.     }
  64. }
  65. # Uninstall Dell Win10 App
  66. $dellapp = "*DellCommandUpdate*"
  67. if (Get-AppxPackage -AllUsers $dellapp) {
  68.     $app = Get-AppxPackage -allusers $dellapp
  69.     Write-Progress -CurrentOperation "$($app.Name) app found. Uninstalling..." -Activity "Uninstalling"
  70.     $app | Remove-AppxPackage -allusers
  71. }
  72. if (Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -like $dellapp}) {
  73.     $provapp = Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -like $dellapp}
  74.     Write-Progress -CurrentOperation "$($provapp.DisplayName) provisioned app found. Uninstalling..." -Activity "Uninstalling"
  75.     $provapp | Remove-AppxProvisionedPackage -Online
  76. }
  77.  
  78. # Install/Upgrade DCU
  79. &$choco upgrade dellcommandupdate -y --no-progress
  80.  
  81. # See what updates are available
  82. Start-Process "$($dcu)\dcu-cli.exe" -ArgumentList "/scan -report=$homepath" -Wait
  83. [xml]$XMLReport = get-content "$homepath\DCUApplicableUpdates.xml"
  84.  
  85. # Delete report because we don't need it anymore, and sometimes fails to overwrite
  86. Remove-Item "$homepath\DCUApplicableUpdates.xml" -Force
  87.  
  88. $AvailableUpdates = $XMLReport.updates.update
  89. $BIOSUpdates        = ($XMLReport.updates.update | Where-Object {$_.type -eq "BIOS"}).name.Count
  90. $ApplicationUpdates = ($XMLReport.updates.update | Where-Object {$_.type -eq "Application"}).name.Count
  91. $DriverUpdates      = ($XMLReport.updates.update | Where-Object {$_.type -eq "Driver"}).name.Count
  92. $FirmwareUpdates    = ($XMLReport.updates.update | Where-Object {$_.type -eq "Firmware"}).name.Count
  93. $OtherUpdates       = ($XMLReport.updates.update | Where-Object {$_.type -eq "Other"}).name.Count
  94. $PatchUpdates       = ($XMLReport.updates.update | Where-Object {$_.type -eq "Patch"}).name.Count
  95. $UtilityUpdates     = ($XMLReport.updates.update | Where-Object {$_.type -eq "Utility"}).name.Count
  96. $UrgentUpdates      = ($XMLReport.updates.update | Where-Object {$_.Urgency -eq "Urgent"}).name.Count
  97. Write-Host "BIOS Updates: $BIOSUpdates"
  98. Write-Host "Application Updates: $ApplicationUpdates"
  99. Write-Host "Driver Updates: $DriverUpdates"
  100. Write-Host "Firmware Updates: $FirmwareUpdates"
  101. Write-Host "Other Updates: $OtherUpdates"
  102. Write-Host "Patch Updates: $PatchUpdates"
  103. Write-Host "Utility Updates: $UtilityUpdates"
  104. Write-Host "Urgent Updates: $UrgentUpdates"
  105.  
  106. # Find and Apply Updates
  107. &"$dcu\DCU-CLI.exe" /applyupdates -updateSeverity="critical,recommended" -autoSuspendBitLocker=enable -reboot=disable
  108.  
  109. # Exit code 500 means no updates found, exit 0 so script doesn't fail
  110. if ($LastExitCode -eq 500) {
  111.     # Check BIOS Version
  112.     $currentbiosversion = Get-WmiObject -Class Win32_BIOS | Select-Object -ExpandProperty SMBIOSBIOSVersion
  113.     $newestbiosversion = ($XMLReport.updates.update | Where-Object { $_.type -eq "BIOS" }).version
  114.     # If there's no newer version we have to assume it's already current
  115.     if ($null -eq $newestbiosversion) {
  116.         $newestbiosversion = "$currentbiosversion"
  117.     }
  118.     "Current BIOS Version: $currentbiosversion"
  119.     "Newest BIOS Version: $newestbiosversion"
  120.     if ($currentbiosversion -eq $newestbiosversion) {
  121.         "BIOS version is current"
  122.         Close-Rmm-Alert -Category "Dell Command Update BIOS Version"
  123.     }
  124.     else {
  125.         "BIOS version is out of date"
  126.         Rmm-Alert -Category "Dell Command Update BIOS Version" -Body "BIOS version is out of date"
  127.     }
  128.     exit 0
  129. }
  130. # LastExitCode 1 means a reboot is required, do exit 0 so script doesn't fail
  131. if ($LastExitCode -eq 1) {
  132.     shutdown /g /f
  133.     exit 0
  134. }
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement