New
#31
No sure about setting the Console properties in PE but try this
Add your Revisions once tested...
Code:<# .DESCRIPTION If a Matching OS and Arch are found then export and integrate drivers .NOTES Author : Superfly Version : 1.0.0.6 Date : 20190707 .REVISION Author : Version : #> if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process PowerShell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs Exit } $console = (Get-Host).UI.RawUI $size = $console.WindowSize $size.Width = 70 $size.Height = 20 $console.WindowSize = $size $console.WindowTitle ='WinPE Driver Integration' $WinPEDrive = $env:SystemDrive -replace ':' $WinPEBuildLabEx = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object -ExpandProperty BuildLabEx $WinPECurrentVersion = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object -ExpandProperty CurrentVersion $WinPECurrentMajorVersionNumber = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object -ExpandProperty CurrentMajorVersionNumber -ErrorAction SilentlyContinue if ($WinPEBuildLabEx.Split('.') -contains 'x86fre') {$WinPEArch = $true} else {$WinPEArch = $false} $Drives = Get-PSDrive -PSProvider FileSystem | Select-Object Name, Root | Where-Object {$_.Name -notcontains $WinPEDrive} $List = @() foreach ($Drive in $Drives) { $HivePath = Join-Path($Drive.Root) -ChildPath "Windows\System32\config\SOFTWARE" if (Test-Path($HivePath)) { Reg.exe Load 'HKLM\TempHive' $HivePath | Out-Null $BuildLabEx = Get-ItemProperty -Path 'HKLM:\TempHive\Microsoft\Windows NT\CurrentVersion' | Select-Object -ExpandProperty BuildLabEx $CurrentVersion = Get-ItemProperty -Path 'HKLM:\TempHive\Microsoft\Windows NT\CurrentVersion' | Select-Object -ExpandProperty CurrentVersion $CurrentMajorVersionNumber = Get-ItemProperty -Path 'HKLM:\TempHive\Microsoft\Windows NT\CurrentVersion' | Select-Object -ExpandProperty CurrentMajorVersionNumber -ErrorAction SilentlyContinue Reg.exe Unload 'HKLM\TempHive'| Out-Null if ($BuildLabEx.Split('.') -contains 'x86fre') {$Arch = $true} else {$Arch = $false} if ($WinPECurrentVersion -eq $CurrentVersion -and $WinPEArch -eq $Arch -and $WinPECurrentMajorVersionNumber -eq $CurrentMajorVersionNumber){ $List += $Drive.Root } } } #User choice export if ($List.Length -gt 0) { $SaveToList = @() $Destination = Join-Path ([Environment]::GetFolderPath("Desktop")) -ChildPath "HostDrivers" $SaveToList += $Destination if(Test-Path("Y:\CDUsb.y")){$SaveToList += Join-Path ("Y:\") -ChildPath "HostDrivers"} $DriverReport = Join-Path ([Environment]::GetFolderPath("Desktop")) -ChildPath "Driver Integration Report.txt" foreach($Item in $List) { Write-Host $Item } $Drive = Read-Host "Choose a Drive letter from the above list from which to export drivers" foreach($Item in $List){ if ($Drive -ne '' -and $Item.StartsWith($Drive.ToUpper())) { $SaveToList += Join-Path ($Item) -ChildPath "HostDrivers" Break } } foreach($Item1 in $SaveToList) { Write-Host $Item1 } $Drive2 = Read-Host "Please Select Drive Letter As Destination For Exported HostDrivers Folder" foreach($Item1 in $SaveToList){ if ($Drive2 -ne '' -and $Item1.StartsWith($Drive2.ToUpper())) { $Destination = $Item1 Break } } Write-Progress -Activity "Please wait while exporting drivers from $Item" Export-WindowsDriver -Path $Item -Destination $Destination | Out-Null #Load Drivers if (Test-Path($Destination)) { Write-host "Drivers saved to $Destination `n" if ((Read-Host "Integrate drivers? Y/N") -eq 'y') { $Files = (Get-ChildItem $Destination -Recurse -Filter "*.inf" | Measure-Object).Count $i = 0 Get-ChildItem $Destination -Recurse -Filter "*.inf" | ForEach-Object { $i++ PNPUtil.exe /add-driver $_.FullName /install Write-Progress -Activity "Integrating drivers" -PercentComplete (($i/$Files) * 100)} | Out-File $DriverReport Write-Host $DriverReport "created" } #Cleanup if ((Test-Path ($Destination)) -and (Read-Host "Delete HostDrivers folder? Y/N") -eq 'y') {Remove-Item $Destination -Recurse -Force} if ((Test-Path ($DriverReport)) -and (Read-Host "Delete Drivers Integration file? Y/N") -eq 'y') {Remove-Item $DriverReport -Force} } } else {Write-Host "No drivers to export"} Write-Host "Done" Read-Host
Last edited by Superfly; 07 Jul 2019 at 15:55. Reason: Updated to 1.0.0.6 to add Breaks to loops