Advertisement
Combreal

Get-LatestCab-Info02.ps1

Nov 26th, 2021
1,024
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function GetCurrentModelVer ($Model) {
  2.     $DriversItems = Get-ChildItem "S:\MDT-Drivers\Windows 10 x64\Dell Inc" | Where-Object {$_.PSIsContainer -eq $true} | Sort-Object
  3.     foreach ($i in $DriversItems)
  4.     {
  5.         If ($i -Like $Model) {
  6.             $Cab = (Get-ChildItem $i.FullName -filter "*.cab").Name
  7.             If($Cab -match '-A\d\d-') {
  8.                 Return $($Matches[0].Substring(1,$Matches[0].Length-2))
  9.             }
  10.         }
  11.     }
  12. }
  13.  
  14. Function GetDellDrivers($CABPage) {
  15.     If ($(Get-CimInstance Win32_Operatingsystem | Select-Object -expand Caption) -Like "*Server*") {
  16.         Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" -Name "IsInstalled" -Value 0
  17.         Stop-Process -Name Explorer -Force
  18.         Start Explorer
  19.     }
  20.     If( -Not $(Test-Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3')) {
  21.         New-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3' -Name '1A10' -value '0' -PropertyType "DWORD" | Out-Null
  22.     }
  23.     Else {
  24.         Set-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3' -Name '1A10' -value '0' | Out-Null
  25.     }
  26.    
  27.     $WebResponse = Invoke-WebRequest $CABPage #-Usebasicparsing
  28.     $counter = 0
  29.     $WebResponse.AllElements | Where {$_.TagName -eq "td"} | Foreach {
  30.         If ($counter -eq 0 -Or ($counter % 4) -eq 0) {
  31.             $Label = $_.innerHTML.Replace("<div>","")
  32.             $Label = $Label.Replace("</div>","")
  33.             $Label = $Label.Replace("<br>","")
  34.             $Label = $Label.Replace("&nbsp;"," ")
  35.             $Label = $Label -replace '<[^>]+>','' #remove HTML code
  36.             $Label = $Label -replace '(^\s+|\s+$)','' -replace '\s+',' ' #remove all spaces at the beginning and end of the line
  37.         }
  38.         ElseIf ($counter -eq 1 -Or ($counter % 4) -eq 1) {
  39.             $URL = $_.innerHTML
  40.             $URL = $URL -replace '<[^>]>',''
  41.             $URL = ((Select-String '(http[s]?)(:\/\/)([^\s,]+)(?=")' -Input $URL).Matches.Value)
  42.             (Invoke-WebRequest -Uri $URL).Links.Href | Sort-Object | Get-Unique | Foreach {
  43.                 If ($_ -Like "*.CAB*") {
  44.                     $DirectURL = $_
  45.                 }
  46.             }
  47.         }
  48.         ElseIf ($counter -eq 2 -Or ($counter % 4) -eq 2) {
  49.             $Version = $_.innerText
  50.             $Version = $Version -replace '<[^>]+>',''
  51.             $Version = $Version -replace '(^\s+|\s+$)','' -replace '\s+',' '
  52.         }
  53.         ElseIf ($counter -eq 3 -Or ($counter % 4) -eq 3) {
  54.             $DriverVersion = GetCurrentModelVer $Label
  55.             If ($DriverVersion -ne $null) {
  56.                 If ($($Version -replace "[^0-9]" , '') -gt $($DriverVersion -replace "[^0-9]" , '')) {
  57.                     #Write-Host "Current Driver version : " $DriverVersion
  58.                     Write-Host $Label "  " $Version "  " $DirectURL
  59.                 }
  60.             }
  61.         }
  62.         $counter++
  63.     }
  64.     $ErrorActionPreference = "SilentlyContinue";
  65.     Get-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3' | Select-Object -ExpandProperty '1001' | Out-Null
  66.     If ($?) {
  67.         Remove-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3' -Name '1A10'
  68.     }
  69.     $ErrorActionPreference = "Continue";      
  70.     If ($(Get-CimInstance Win32_Operatingsystem | Select-Object -expand Caption) -Like "*Server*") {
  71.         Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" -Name "IsInstalled" -Value 1
  72.         Stop-Process -Name Explorer -Force
  73.         Start Explorer
  74.     }
  75. }
  76.  
  77. GetDellDrivers "https://www.dell.com/support/kbdoc/fr-fr/000109893/packs-de-pilotes-dell-command-deploy-pour-mod%C3%A8les-latitude"
  78. #GetDellDrivers "https://www.dell.com/support/kbdoc/000109842/dell-command-deploy-driver-packs-for-precision-models"
  79. #GetDellDrivers "https://www.dell.com/support/kbdoc/000109959/dell-command-deploy-driver-packs-for-xps-models" #errors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement