App Development Help

Page 3 of 4 FirstFirst 1234 LastLast

  1. Posts : 4,144
    Windows 3.1 to Windows 11
    Thread Starter
       #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
    Attached Thumbnails Attached Thumbnails App Development Help-image75.jpg  
      My Computer


  2. Posts : 3,453
       #22

    Well with all the different versions going around, here is a base 1.0.0.0 to work from - I added the export and integrate stuff as well

    Code:
    <#  
    
    .DESCRIPTION
        If a Matching OS and Arch are found then export and integrate drivers
    
    .NOTES  
        Author     : Superfly
        Version    : 1.0.0.0 (20190705 Initial Build)  
    
    .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
    }
    
    $WinPEDrive =  $env:SystemDrive -replace ':'
    
    $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}
    
    $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
            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){
    
                $List += ($HivePath.Replace("Windows\System32\config\SOFTWARE", ''))
             
                } 
            else {   
                
                Write-Host "No drivers to export "
            }
        }
    }
    
    #User choice export
    
    $Destination = Join-Path ([Environment]::GetFolderPath("Desktop")) -ChildPath "HostDrivers"
    
    foreach($Item in $List) { Write-Host $Item }
    
        Write-Host "`r`n"
        $Drive = Read-Host "Choose a Drive letter from the above list from which to export..." 
        Write-Host "`r`n"
    
    
        foreach($Item in $List){
            if ($Item.StartsWith($Drive.ToUpper())) {
            Write-Host "Please wait while exporting drivers from" $Item
            Export-WindowsDriver -Path $Item   -Destination $Destination #| Out-Null
            }
        }
    
    #Load Drivers
    $confirmation = Read-Host "Type 'Y' if you want to integrate drivers?"
    if ($confirmation -eq 'y') {
        Get-ChildItem $Destination -Recurse -Filter "*.inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install }
    }
    Write-Host "Done"
    Read-Host
      My Computer


  3. Posts : 4,144
    Windows 3.1 to Windows 11
    Thread Starter
       #23

    Very Good... But...
    We have two working processes we have to Merge....

    Feedback RE: 1.0.0.0 (20190705 Initial Build)
    Pro - Export & Import works Great
    Con - Lists All OS's Found (Test Results 5 )

    Feedback about below Code
    Pro - Lists ONLY Matching OS's (Test Results 2)
    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 = 'X'  # 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
    Needs to List ONLY Matching OS's and Ask which Matching OS to Export Drivers From..
    Need to Merge CodeBox Matching Process with Version : 1.0.0.0 (20190705 Initial Build) Export Process..

    ****************************
    It is in this section here From inside Codebox

    Code:
     #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 "
             }
    If Write-Host Message = Export drivers From *:\Windows\System32\Drivers
    List Drive as User Choice Export Option
    Else ( Disregard )

    And then follow Build Version : 1.0.0.0 (20190705 Initial Build)
    #User choice export

    One other small request > can we pipe the #Load Drivers process into a %UserProfile%\Desktop\Driver Integration Report.txt file
    Last edited by Kyhi; 05 Jul 2019 at 17:17.
      My Computer


  4. Posts : 3,453
       #24

    v1.0.0.1


    Code:
    <#  
    
    .DESCRIPTION
        If a Matching OS and Arch are found then export and integrate drivers
    
    .NOTES  
        Author     : Superfly
        Version    : 1.0.0.1 
        Date       : 20190706 
    
    .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
    }
    
    $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
    
    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
            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){
    
                $List += $Drive.Root
             
                } 
    
        }
    }
    
    #User choice export
    if ($List.Length -gt 0) {
    
    $Destination = Join-Path ([Environment]::GetFolderPath("Desktop")) -ChildPath "HostDrivers"
    $DriverReport = Join-Path ([Environment]::GetFolderPath("Desktop")) -ChildPath "Driver Integration Report.txt"
    
    foreach($Item in $List) { Write-Host $Item }
    
        Write-Host "`r`n"
        $Drive = Read-Host "Choose a Drive letter from the above list from which to export..." 
    
        foreach($Item in $List){
            if ($Drive -ne '' -and $Item.StartsWith($Drive.ToUpper())) {
            Write-Host "Please wait while exporting drivers from" $Item
            Export-WindowsDriver -Path $Item -Destination $Destination | Out-Null
            }
        }
    
    #Load Drivers
    if (Test-Path($Destination)) {
        $confirmation = Read-Host "Type 'Y' if you want to integrate drivers?"
        if ($confirmation -eq 'y' ) {
            Get-ChildItem $Destination -Recurse -Filter "*.inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install } | Out-File $DriverReport 
            }
        }
    }
            
    else {   
         Write-Host "No drivers to export "
    }
    
    
    Write-Host "Done"
    Read-Host
      My Computer


  5. Posts : 4,144
    Windows 3.1 to Windows 11
    Thread Starter
       #25

    Re: Version : 1.0.0.1

    This is 100% What We Needed... And is Very Usable To Us...
    App Development Help-image78.jpg

    But :: (there always is)
    1) Can you Add message after Question = Y > "Integrating Host Drivers - Please Wait"
    As currently due to no window output - the program appears frozen

    2) can you add $Item1 as #User choice Destination - Option as part of #User choice export
    To include Message "Please Select Destination For Exported HostDrivers Folder"
    $Item1 list to include
    $Drive that where found matching
    Current Desktop ( which you have already included > Ram X:\ )
    And If Exist File Y:\CDUsb.y - Destination Drive Item Y:\ - ( which is our "CDUsb Boot Drive" )

    3) can you add #User choice Remove Destination Folder - At End

    Reason being this will allow user to select option to Place Exported Drivers folder outside of RAM
    And also allow user to remove that drivers folder when integration complete...
    with x86 we have 1024MB WinPE Cache limitation - After Export-Import - I had 199MB available Cache remaining and After deleting Host drivers folder - I had 513MB Cache Available....

    End of But ::

    Messaging
    Choose a Drive letter from the above list from which to export Drivers...
    Type 'Y' if you want to integrate the Exported Drivers?
    Please Select Destination For Exported HostDrivers Folder (ie $Item1 List)
    Please wait - Exporting drivers from $Item
    Integrating Host Drivers from $Item1\HostDrivers - Please Wait
    Do You Want To remove the Folder $Item1\HostDrivers?
    Done - Driver Integration Report Written To Desktop
    App Development Help Attached Files
    Last edited by Kyhi; 06 Jul 2019 at 09:49.
      My Computer


  6. Posts : 4,144
    Windows 3.1 to Windows 11
    Thread Starter
       #26

    Can you Set PowerShell "Properties" To when running script
    Windows Size > Width 70 - Height 20
    Colors > Screen text White - Screen Background Dark Blue
      My Computer


  7. Posts : 4,144
    Windows 3.1 to Windows 11
    Thread Starter
       #27

    Also just realized while testing in x64
    It does not seem to match OS... ( CurrentVersion )
    Just Arch...
    As it listed my Windows 8.1 drive
    Last edited by Kyhi; 06 Jul 2019 at 17:26.
      My Computer


  8. Posts : 3,453
       #28

    Kyhi said:
    Also just realized while testing in x64
    It does not seem to match OS... ( CurrentVersion )
    Just Arch...
    As it listed my Windows 8.1 drive
    Yup MS were too lazy to remove the Win 8.1 kernel version (6.3) in Win 10....updated now to check for Win 10 kernel version

    Code:
    <#  
    
    .DESCRIPTION
        If a Matching OS and Arch are found then export and integrate drivers
    
    .NOTES  
        Author     : Superfly
        Version    : 1.0.0.2 
        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
    }
    
    $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) {
    
    $Destination = Join-Path ([Environment]::GetFolderPath("Desktop")) -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())) {
            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
            }
            #Cleanup 
            if ((Test-Path ($Destination)) -and (Read-Host "Delete Drivers folder? Y/N") -eq 'y') {Remove-Item $Destination -Recurse}
            if ((Test-Path ($DriverReport)) -and (Read-Host "Delete Drivers Integration file? Y/N")  -eq 'y') {Remove-Item $DriverReport}
        }
    }
            
    else {Write-Host "No drivers to export"}
    
    Write-Host "Done"
    
    Read-Host
      My Computer


  9. Posts : 4,144
    Windows 3.1 to Windows 11
    Thread Starter
       #29

    Matching Works Properly...
    Integration Works Properly...
    Activity Progress Bar - Nice Touch..
    Driver Report Works Properly..
    Clean Up Works Properly..

    User Choice Destination Option ??

    PS Console Defaults ??
    App Development Help-screenshot00002.jpg

    Reason Being Script Is Run From Shortcut ( *\powershell.exe -file *\winpedriver.ps1 ) and opens full screen due to PE display resolution

    Also Revised 1.0.0.3 > Edited Messages
    App Development Help-screenshot00001.jpg

    Code:
    <#  
    .DESCRIPTION
        If a Matching OS and Arch are found then export and integrate drivers
    .NOTES  
        Author     : Superfly
        Version    : 1.0.0.2 
        Date       : 20190707 
    .REVISION  
        Author     : Kyhi
        Version    : 1.0.0.3 
    #> 
    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 =  $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) {
    $Destination = Join-Path ([Environment]::GetFolderPath("Desktop")) -ChildPath "HostDrivers"
    $DriverReport = Join-Path ([Environment]::GetFolderPath("Desktop")) -ChildPath "Driver Integration Report.txt"
    foreach($Item in $List) { Write-Host $Item }
    $Drive = Read-Host "Matching OS Found Choose A Drive Letter To Export Drivers From" 
        foreach($Item in $List){
            if ($Drive -ne '' -and $Item.StartsWith($Drive.ToUpper())) {
            Write-Progress -Activity "Drivers Are Being Exported From $Item"
            Export-WindowsDriver -Path $Item -Destination $Destination | Out-Null
            }
        }
    #Load Drivers
        if (Test-Path($Destination)) {
            Write-host "Exported Drivers Saved To $Destination `n" 
            if ((Read-Host "Do You Want To 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 Host Drivers" -PercentComplete (($i/$Files) * 100)} | Out-File $DriverReport
            }
            #Cleanup 
            if ((Test-Path ($Destination)) -and (Read-Host "Do You Want To Delete The HostDrivers Folder? Y/N") -eq 'y') {Remove-Item $Destination -Recurse}
            if ((Test-Path ($DriverReport)) -and (Read-Host "Do You Want To Delete The Drivers Integration Report? Y/N")  -eq 'y') {Remove-Item $DriverReport}
        }
    }
            
    else {Write-Host "No Drivers To Export"}
    Write-Host "Done"
    Read-Host
      My Computer


  10. Posts : 4,144
    Windows 3.1 to Windows 11
    Thread Starter
       #30

    Revised 1.0.0.4
    > Added " Devcon.exe /restart * "
    Question, Process and Messages

    Code:
    <#  
    .DESCRIPTION
        If a Matching OS and Arch are found then export and integrate drivers
    .NOTES  
        Author     : Superfly
        Version    : 1.0.0.2 
        Date       : 20190707 
    .REVISION  
        Author     : Kyhi
        Version    : 1.0.0.4 
    #> 
    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 =  $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) {
    $Destination = Join-Path ([Environment]::GetFolderPath("Desktop")) -ChildPath "HostDrivers"
    $DriverReport = Join-Path ([Environment]::GetFolderPath("Desktop")) -ChildPath "Driver Integration Report.txt"
    $DevconReport = Join-Path ([Environment]::GetFolderPath("Desktop")) -ChildPath "Devcon Resetting Report.txt"
    foreach($Item in $List) { Write-Host $Item }
    $Drive = Read-Host "Matching OS Found Choose A Drive Letter To Export Drivers From" 
        foreach($Item in $List){
            if ($Drive -ne '' -and $Item.StartsWith($Drive.ToUpper())) {
            Write-Progress -Activity "Drivers Are Being Exported From $Item"
            Export-WindowsDriver -Path $Item -Destination $Destination | Out-Null
            }
        }
    #Load Drivers
        if (Test-Path($Destination)) {
            Write-host "Exported Drivers Saved To $Destination `n" 
            if ((Read-Host "Do You Want To 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 Host Drivers" } | Out-File $DriverReport
            if ((Read-Host "Do You Want Devcon To Reset Drivers? Y/N")  -eq 'y') {
            Write-Progress -Activity "Devcon Resetting Drivers"
            Devcon.exe restart * | Out-File $DevconReport }
            }
            #Cleanup 
            if ((Test-Path ($Destination)) -and (Read-Host "Do You Want To Delete The HostDrivers Folder? Y/N") -eq 'y') {Remove-Item $Destination -Recurse}
            if ((Test-Path ($DriverReport)) -and (Read-Host "Do You Want To Delete The Drivers Integration Report? Y/N")  -eq 'y') {Remove-Item $DriverReport}
            if ((Test-Path ($DevconReport)) -and (Read-Host "Do You Want To Delete The Devcon Resetting Report? Y/N")  -eq 'y') {Remove-Item $DevconReport}
        }
    }
            
    else {Write-Host "No Drivers To Export"}
    Write-Host "Done"
    Read-Host
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 19:58.
Find Us




Windows 10 Forums