New
#21
This one works for me (Not Post 12)
Code: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 } $WinPEDrive = 'C' # Note: Change to $WinPEDrive = 'X' if running this script in WinPE $WinPEProduct = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object -ExpandProperty ProductName $WinPEArch = 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 if ($WinPEArch.Split(".") -contains 'x86fre') {$WinPEArch = $true} else {$WinPEArch = $false} $Drives = Get-PSDrive -PSProvider FileSystem | Select-Object Name, Root | Where-Object {$_.Name -notcontains $WinPEDrive} 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 $ProductName = Get-ItemProperty -Path 'HKLM:\TempHive\Microsoft\Windows NT\CurrentVersion' | Select-Object -ExpandProperty ProductName $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 Reg.exe Unload 'HKLM\TempHive'| Out-Null if ($BuildLabEx.Split(".") -contains 'x86fre') {$Arch = $true} else {$Arch = $false} #If a Matching OS and Arch are found then export and integrate drivers if ($WinPECurrentVersion -eq $CurrentVersion -and $WinPEArch -eq $Arch){ Write-Host "Export drivers from " $HivePath.Replace("config\SOFTWARE", "Drivers") } else { Write-Host "No drivers to export " } } } Write-Host "Done" Read-Host