Provisioning/Invoke-OSDCloudDriverPack.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
#================================================= #region Start Transcript if (Test-Path "$env:Windir\debug") { $Global:Transcript = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Invoke-OSDCloudDriverPack.log" Start-Transcript -Path (Join-Path "$env:Windir\debug" $Global:Transcript) -ErrorAction Ignore } #endregion #================================================= #region Apply OSDCloud DriverPack if (Test-Path 'C:\Drivers') { $DriverPacks = Get-ChildItem -Path 'C:\Drivers' -File foreach ($Item in $DriverPacks) { $ExpandFile = $Item.FullName Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Reviewing $ExpandFile" $DestinationPath = Join-Path $Item.Directory $Item.BaseName #================================================= # Zip #================================================= if ($Item.Extension -eq '.zip') { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Processing actions for ZIP file" if (Test-Path "$DestinationPath") { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) DriverPack has already been extracted" } else { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Expanding ZIP DriverPack to $DestinationPath" Expand-Archive -Path $ExpandFile -DestinationPath $DestinationPath -Force Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Applying DriverPack with PNPUNATTEND" New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths" -Name 1 -Force New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths\1" -Name Path -Value $DestinationPath -Force pnpunattend.exe AuditSystem /L Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths\1" -Recurse -Force } Continue } #================================================= # Cab #================================================= if ($Item.Extension -eq '.cab') { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Processing actions for CAB file" if (Test-Path "$DestinationPath") { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) DriverPack has already been extracted" } else { New-Item $DestinationPath -ItemType Directory -Force -ErrorAction Ignore | Out-Null Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Expanding CAB DriverPack to $DestinationPath" Expand -R "$ExpandFile" -F:* "$DestinationPath" | Out-Null Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Applying DriverPack with PNPUNATTEND" New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths" -Name 1 -Force New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths\1" -Name Path -Value $DestinationPath -Force pnpunattend.exe AuditSystem /L Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths\1" -Recurse -Force } Continue } #================================================= # Dell EXE #================================================= if ($Item.Extension -eq '.exe') { if ($Item.VersionInfo.FileDescription -match 'Dell') { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Processing actions for Dell EXE file" Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) FileDescription: $($Item.VersionInfo.FileDescription)" Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) ProductVersion: $($Item.VersionInfo.ProductVersion)" if (Test-Path "$DestinationPath") { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) DriverPack has already been extracted" } else { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Expanding Dell DriverPack to $DestinationPath" $null = New-Item -Path $DestinationPath -ItemType Directory -Force -ErrorAction Ignore | Out-Null Start-Process -FilePath $ExpandFile -ArgumentList "/s /e=`"$DestinationPath`"" -Wait Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Applying DriverPack with PNPUNATTEND" New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths" -Name 1 -Force New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths\1" -Name Path -Value $DestinationPath -Force pnpunattend.exe AuditSystem /L Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths\1" -Recurse -Force } Continue } } #================================================= # HP #================================================= if ($Item.Extension -eq '.exe') { if (($Item.VersionInfo.InternalName -match 'hpsoftpaqwrapper') -or ($Item.VersionInfo.OriginalFilename -match 'hpsoftpaqwrapper.exe') -or ($Item.VersionInfo.FileDescription -like "HP *")) { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Processing actions for HP EXE file" Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) FileDescription: $($Item.VersionInfo.FileDescription)" Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) ProductVersion: $($Item.VersionInfo.ProductVersion)" Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) InternalName: $($Item.VersionInfo.InternalName)" Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) OriginalFilename: $($Item.VersionInfo.OriginalFilename)" if (Test-Path "$DestinationPath") { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) DriverPack has already been extracted" } else { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Expanding HP DriverPack to $DestinationPath" Start-Process -FilePath $ExpandFile -ArgumentList "/s /e /f `"$DestinationPath`"" -Wait Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Applying DriverPack with PNPUNATTEND" New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths" -Name 1 -Force New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths\1" -Name Path -Value $DestinationPath -Force pnpunattend.exe AuditSystem /L Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths\1" -Recurse -Force } Continue } } #================================================= # Lenovo #================================================= if ($Item.Extension -eq '.exe') { if (($Item.VersionInfo.FileDescription -match 'Lenovo') -or ($Item.Name -match 'tc_') -or ($Item.Name -match 'tp_') -or ($Item.Name -match 'ts_') -or ($Item.Name -match '500w') -or ($Item.Name -match 'sccm_') -or ($Item.Name -match 'm710e') -or ($Item.Name -match 'tp10') -or ($Item.Name -match 'tp8') -or ($Item.Name -match 'yoga')) { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Processing actions for Lenovo EXE file" Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) FileDescription: $($Item.VersionInfo.FileDescription)" Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) ProductVersion: $($Item.VersionInfo.ProductVersion)" $DestinationPath = Join-Path $Item.Directory 'SCCM' if (Test-Path "$DestinationPath") { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) DriverPack has already been extracted" } else { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Expanding Lenovo DriverPack to $DestinationPath" Start-Process -FilePath $ExpandFile -ArgumentList "/SILENT /SUPPRESSMSGBOXES" -Wait Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Applying DriverPack with PNPUNATTEND" New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths" -Name 1 -Force New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths\1" -Name Path -Value $DestinationPath -Force pnpunattend.exe AuditSystem /L Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UnattendSettings\PnPUnattend\DriverPaths\1" -Recurse -Force } Continue } } #================================================= # MSI #================================================= if ($Item.Extension -eq '.msi') { Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Processing actions for MSI file" $DateStamp = Get-Date -Format yyyyMMddTHHmmss $logFile = '{0}-{1}.log' -f $ExpandFile,$DateStamp $MSIArguments = @( "/i" ('"{0}"' -f $ExpandFile) "/qb" "/norestart" "/L*v" $logFile ) Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow Continue } #================================================= # Everything Else #================================================= Write-Verbose -Verbose "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) File does not appear to be a DriverPack" #================================================= } } #================================================= #region End Transcript if (Test-Path "$env:Windir\debug") { Stop-Transcript -ErrorAction Ignore } #endregion #================================================= |