Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ####################################################
  2. # Checks.ps1
  3. $Version = "1.0.11"
  4. $Date = "5.12.2018"
  5. # Updated: 5 Dec 2018
  6. # Author: Luke Stanley-Ryan.
  7. # Summary: This Script pre-installs required Firmware Updates and settings.
  8. # Pre-Requisites: Designed to run under WinPE.
  9. ####################################################
  10. Write-Host "Script Version $Version, updated: $Date"
  11. Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
  12. #Grab mount point of the USB drive for pointing to locations dynamically.
  13. $currentDrive = (Get-Location).ToString().Substring(0,2)
  14. $Model = (Get-WmiObject -Class Win32_ComputerSystem).Model
  15. $Battery = (Get-WmiObject Win32_battery).EstimatedChargeRemaining
  16. $Mem = (Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory
  17. #Add to these and copy/edit code blocks to support more devices.
  18. $1040 = "HP EliteBook Folio 1040 G3"
  19. $MFF = "HP EliteDesk 800"
  20. $x2 = "HP Elite x2"
  21. $840 = "HP EliteBook 840 G3"
  22. #Change these as the BIOS version being upgraded to changes.
  23. $1040G3BIOS = "N83 Ver. 01.33"
  24. $MFFBIOS = "N21 Ver. 02.36"
  25. $x2BIOS = "N85 Ver. 01.33"
  26. $840G3BIOS = "N75 Ver. 01.25"
  27. #Change these as TPM version being upgraded to changes.
  28. $TPMVerTo = "7.62"
  29. $TPMSpecTo = "2.0"
  30.  
  31. #I7 devices should be put aside for people who moan about getting I5.
  32. if (($Model -match $1040) -and ((Get-WmiObject Win32_Processor | Select-Object -ExpandProperty Name) -match "i7")){
  33.     Write-Host "Device has an I7 Processor" -ForegroundColor Cyan
  34.     Start-Sleep -s 1
  35. }
  36. elseif ($Model -match $1040){
  37.     Write-Host "Device has an I5 Processor" -ForegroundColor Cyan
  38.     Start-Sleep -s 1
  39. }
  40.  
  41. #Tells you how much memory the device has.
  42. if ($Mem -lt 10000000000){
  43.     $Ram = $Mem.ToString().SubString(0,1)
  44. }
  45. elseif ($Mem -lt 100000000000){
  46.     $Ram = $Mem.ToString().SubString(0,2)
  47. }
  48. else {
  49.     $Ram = $Mem.ToString().SubString(0,3)
  50. }
  51.  
  52. Write-Host "Device has a total of $Ram`GB of Physical Memory" -ForegroundColor Yellow
  53.  
  54. #Determine if device needs to be plugged into AC Power before Firmware/BIOS updates.
  55. if ($Model -match $MFF){
  56.     Write-Host "Device is on AC Power..." -ForegroundColor Green}
  57. elseif ((Get-WmiObject -Class Win32_Battery).BatteryStatus -ne 1){
  58.     Write-Host "Device is on AC Power..." -ForegroundColor Green}
  59. elseif ($Battery -lt 26){
  60.     Write-Host "$Battery`% battery remaining, Plug AC Power in before BIOS and Firmware updates..." -ForegroundColor Red
  61.     Read-Host "Press <Enter> to continue..."} #Prompt the user if the battery is critically low.
  62. elseif ($Battery -lt 51){
  63.     Write-Host "$Battery`% battery remaining, Recommend plugging AC Power in before BIOS and Firmware updates..." -ForegroundColor Yellow}
  64. elseif ($Battery -lt 76){
  65.     Write-Host "$Battery`% battery remaining..." -ForegroundColor Cyan}
  66. else {
  67.     Write-Host "$Battery`% battery remaining..." -ForegroundColor Green
  68. }
  69.  
  70. #Configure UEFI BIOS settings for updates, needs to be configured to run BIOS and TPM updates.
  71. Write-Host "`nPart 1 - Updating BIOS Settings..." -ForegroundColor Black -BackgroundColor White
  72. Set-Location -path "$currentDrive\HP-BCU"
  73. cmd /c "BiosConfigUtility64.exe /cspwdfile:`"Old.txt`" /npwdfile:`"`""
  74. cmd /c "BiosConfigUtility64.exe /setdefaults"
  75. cmd /c "BiosConfigUtility64.exe /set:`"Settings.txt`""
  76.  
  77. #Check if the Intel ME Firmware requires an update and run it to patch security vulnerability.
  78. Set-Location -path "$currentDrive\IntelME-FW"
  79. Write-Host "`nPart 2 - Updating Intel Management Engine (ME) Firmware if required..." -ForegroundColor Black -BackgroundColor White
  80. cmd /c "update64.bat"
  81.  
  82. #Check to see if any drives are encrypted with BitLocker, USB should never be encrypted so it won't get wiped.
  83. Write-Host "`nPart 3 - Formatting Encrypted Drives if required..." -ForegroundColor Black -BackgroundColor White
  84. if (Get-BitLockerVolume -ErrorAction SilentlyContinue | Where-Object VolumeStatus -ne "FullyDecrypted") {
  85.     $EncDrives = (Get-BitLockerVolume -ErrorAction SilentlyContinue | Where-Object VolumeStatus -ne "FullyDecrypted" | Select-Object -ExpandProperty MountPoint | Out-String).SubString(0,1)
  86.     foreach ($EncDrive in $EncDrives) {
  87.         #Format any drives that are encrypted with BitLocker so BIOS and TPM Firmware updates work correctly.
  88.         Format-Volume -DriveLetter $EncDrive -FileSystem NTFS
  89.         Write-Host "$EncDrive`: drive has been formatted..." -ForegroundColor Green
  90.     }
  91. }
  92. else {
  93.     Write-Host "No Encrypted Drives found." -ForegroundColor Magenta
  94. }
  95.  
  96. #Check if BIOS needs updating by checking what model the device is and if the current BIOS version is the most up to date, needs to be updated as BIOS updates are released.
  97. #Automatic check only supports 1040 G3's, 840 G3's, MFF's, and x2's. If other device models are used the script needs to be updated or BIOS update needs to be called manually.
  98. Set-Location -path "$currentDrive\Hp-BIOS-FW"
  99. if ((Get-WmiObject -Namespace root\cimv2\security\microsofttpm -Class Win32_Tpm | Select-Object SpecVersion) -match ".*=(.*?),.*"){$TPMSpec = $matches.1}
  100. $Ver = (Get-WmiObject -Class win32_BIOS).SMBIOSBIOSVersion
  101. $TPMVer = (Get-WmiObject -Namespace root\cimv2\security\microsofttpm -Class Win32_Tpm | Select-Object -ExpandProperty ManufacturerVersion) #Pulls the TPM Version number.
  102. if ($Model -match $1040){
  103.     Write-Host "`nPart 4 - Updating HP System BIOS to $1040G3BIOS if required..." -ForegroundColor Black -BackgroundColor White
  104.     Write-host "Model is $Model, $Ver, TPM is Spec $TPMSpec, Version $TPMVer" -ForegroundColor Cyan
  105.     if ($Ver -ne $1040G3BIOS){
  106.         Write-Host "`nPreparing BIOS update to $1040G3BIOS..." -ForegroundColor Cyan
  107.         cmd /c "HPBIOSUPDREC64.exe -r -s -bloverride" #1040 G3 check.
  108.         Write-Host "`nBIOS Update to $1040G3BIOS prepared..." -ForegroundColor Green
  109.     }
  110.     else {
  111.         Write-Host "`nSystem BIOS already updated to $1040G3BIOS..." -ForegroundColor Green
  112.     }
  113. }
  114. elseif ($Model -match $MFF){
  115.     Write-Host "`nPart 4 - Updating HP System BIOS to $MFFBIOS if required..." -ForegroundColor Black -BackgroundColor White
  116.     Write-host "Model is $Model, $Ver, TPM is Spec $TPMSpec, Version $TPMVer" -ForegroundColor Cyan
  117.     if ($Ver -ne $MFFBIOS){
  118.         Write-Host "`nPreparing BIOS update to $MFFBIOS..." -ForegroundColor Cyan
  119.         cmd /c "HPBIOSUPDREC64.exe -r -s -bloverride" #MFF check.
  120.         Write-Host "`nBIOS Update to $MFFBIOS prepared..." -ForegroundColor Green
  121.     }
  122.     else {
  123.         Write-Host "`nSystem BIOS already updated to $MFFBIOS..." -ForegroundColor Green
  124.     }
  125. }
  126. elseif ($Model -match $x2){
  127.     Write-Host "`nPart 4 - Updating HP System BIOS to $x2BIOS if required..." -ForegroundColor Black -BackgroundColor White
  128.     Write-host "Model is $Model, $Ver, TPM is Spec $TPMSpec, Version $TPMVer" -ForegroundColor Cyan
  129.     if ($Ver -ne $x2BIOS){
  130.         Write-Host "`nPreparing BIOS update to $x2BIOS..." -ForegroundColor Cyan
  131.         cmd /c "HPBIOSUPDREC64.exe -r -s -bloverride" #x2 check.
  132.         Write-Host "`nBIOS Update to $x2BIOS prepared..." -ForegroundColor Green
  133.     }
  134.     else {
  135.         Write-Host "`nSystem BIOS already updated to $x2BIOS..." -ForegroundColor Green
  136.     }
  137. }
  138. elseif ($Model -match $840){
  139.     Write-Host "`nPart 4 - Updating HP System BIOS to $840G3BIOS if required..." -ForegroundColor Black -BackgroundColor White
  140.     Write-host "Model is $Model, $Ver, TPM is Spec $TPMSpec, Version $TPMVer" -ForegroundColor Cyan
  141.     if ($Ver -ne $840G3BIOS){
  142.         Write-Host "`nPreparing BIOS update to $840G3BIOS..." -ForegroundColor Cyan
  143.         cmd /c "HPBIOSUPDREC64.exe -r -s -bloverride" #840 G3 check, added 28.09.18 in case 840 G3's are used for meeting rooms.
  144.         Write-Host "`nBIOS Update to $840G3BIOS prepared..." -ForegroundColor Green
  145.     }
  146.     else {
  147.         Write-Host "`nSystem BIOS already updated to $840G3BIOS..." -ForegroundColor Green
  148.     }
  149. }
  150. else {
  151.     Write-Host "$Model is not supported for automatic BIOS update. supported devices are:`n$1040`n$840`n$x2`n$MFF" -ForegroundColor Yellow
  152. }
  153.  
  154. Write-Host "`nPart 5 - Updating Trusted Platform Module (TPM) Firmware to Spec $TPMSpecTo, Version $TPMVerTo if required..." -ForegroundColor Black -BackgroundColor White
  155. #Check that the TPM version is 7.62 to patch security vulnerability, update it to 7.62 if it is not. If the TPM version we are updating to gets updated, the $TPM*To varibles need to be updated to reflect that.
  156. Set-Location -path "$currentDrive\HP-TPM-FW"
  157. if ($TPMVer -lt $TPMVerTo){
  158.     $FileList = ((Get-ChildItem -Path "$currentDrive\HP-TPM-FW").Name)
  159.     foreach ($File in $FileList){
  160.         if (($File -match ".BIN") -and ($File -match "$TPMVer")){
  161.             cmd /c "TPMConfig64.exe -c -s -f$File" #-c = Create recovery partition if not present, -s = silent, -f[filename] = update version to use - required to use -s.
  162.             Write-Host "TPM Update to Spec: $TPMSpecTo, Version: $TPMVerTo prepared..." -ForegroundColor Cyan
  163.         }
  164.     }
  165.     #Restarts the device so all the Firmware updates can apply.
  166.     Start-Sleep -s 2
  167.     Restart-Computer -Force -ErrorAction SilentlyContinue
  168.     Start-Sleep -s 5
  169. }
  170.  
  171. #Restarts the device so BIOS can update, stops the device from looping if it is already updated.
  172. if ($Model -match $1040){
  173.     if ($Ver -ne $1040G3BIOS){
  174.     Write-Host "BIOS Update to $1040G3BIOS Prepared, TPM Already Updated to Spec: $TPMSpec, Version: $TPMVer..." -ForegroundColor Cyan
  175.     Start-Sleep -s 2
  176.     Restart-Computer -Force -ErrorAction SilentlyContinue
  177.     }
  178.     else {
  179.         Write-Host "BIOS Already Updated to $1040G3BIOS, TPM already updated to Spec $TPMSpec, Version $TPMVer..." -ForegroundColor Green
  180.         Read-Host -prompt "`nPress <Enter> to Restart..."
  181.         Restart-Computer -Force -ErrorAction SilentlyContinue
  182.     }
  183. }
  184. elseif ($Model -match $MFF){
  185.     if ($Ver -ne $MFFBIOS){
  186.     Write-Host "BIOS Update to $MFFBIOS Prepared, TPM Already Updated to Spec: $TPMSpec, Version: $TPMVer..." -ForegroundColor Cyan
  187.     Start-Sleep -s 2
  188.     Restart-Computer -Force -ErrorAction SilentlyContinue
  189.     }
  190.     else {
  191.         Write-Host "BIOS Already Updated to $MFFBIOS, TPM already updated to Spec $TPMSpec, Version $TPMVer..." -ForegroundColor Green
  192.         Read-Host -prompt "`nPress <Enter> to Restart..."
  193.         Restart-Computer -Force -ErrorAction SilentlyContinue
  194.     }
  195. }
  196. elseif ($Model -match $x2){
  197.     if ($Ver -ne $x2BIOS){
  198.     Write-Host "BIOS Update to $x2BIOS Prepared, TPM Already Updated to Spec: $TPMSpec, Version: $TPMVer..." -ForegroundColor Cyan
  199.     Start-Sleep -s 2
  200.     Restart-Computer -Force -ErrorAction SilentlyContinue
  201.     }
  202.     else {
  203.         Write-Host "BIOS Already Updated to $x2BIOS, TPM already updated to Spec $TPMSpec, Version $TPMVer..." -ForegroundColor Green
  204.         Read-Host -prompt "`nPress <Enter> to Restart..."
  205.         Restart-Computer -Force -ErrorAction SilentlyContinue
  206.     }
  207. }
  208. elseif ($Model -match $840){
  209.     if ($Ver -ne $840G3BIOS){
  210.     Write-Host "BIOS Update to $840G3BIOS Prepared, TPM Already Updated to Spec: $TPMSpec, Version: $TPMVer..." -ForegroundColor Cyan
  211.     Start-Sleep -s 2
  212.     Restart-Computer -Force -ErrorAction SilentlyContinue
  213.     }
  214.     else {
  215.         Write-Host "BIOS Already Updated to $840G3BIOS, TPM already updated to Spec $TPMSpec, Version $TPMVer..." -ForegroundColor Green
  216.         Read-Host -prompt "`nPress <Enter> to Restart..."
  217.         Restart-Computer -Force -ErrorAction SilentlyContinue
  218.     }
  219. }
  220. else {
  221.     Write-Host "$Model is not supported for automatic BIOS update. supported devices are:`n$1040`n$840`n$x2`n$MFF" -ForegroundColor Yellow
  222.     Read-Host -prompt "`nPress <Enter> to Restart..."
  223.     Restart-Computer -Force -ErrorAction SilentlyContinue
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement