App Development Help

Page 4 of 4 FirstFirst ... 234

  1. Posts : 3,453
       #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
      My Computer


  2. Posts : 4,143
    Windows 3.1 to Windows 11
    Thread Starter
       #32

    That Is It !!!
    Now would like to change line
    Code:
    $Destination = Join-Path ([Environment]::GetFolderPath("Desktop")) -ChildPath "HostDrivers"
    to Read or set location ( $WinPEDrive -ChildPath "HostDrivers" ) ie X:\HostDrivers

    And add double line break or separator after each question before displaying new choice list..

    App Development Help-screenshot00002.jpg

    That is Now the Console Size on XPE default resolution
      My Computer


  3. Posts : 4,143
    Windows 3.1 to Windows 11
    Thread Starter
       #33

    Now this line is EXACTLY as I had asked you to do...
    Code:
    if(Test-Path("Y:\CDUsb.y")){$SaveToList += Join-Path ("Y:\") -ChildPath "HostDrivers"}
    But now think a Perfected way would be to search for CDUsb.y on the root of any drive and then assign drive letter to list... That way user can insert USB with that CDUsb.y flag on root and use it no matter drive letter assignment
      My Computer


  4. Posts : 4,143
    Windows 3.1 to Windows 11
    Thread Starter
       #34

    Kyhi said:
    That Is It !!!
    Now would like to change line
    Code:
    $Destination = Join-Path ([Environment]::GetFolderPath("Desktop")) -ChildPath "HostDrivers"
    to Read or set location ( $WinPEDrive -ChildPath "HostDrivers" ) ie X:\HostDrivers

    And add double line break or separator after each question before displaying new choice list..
    I figured them both out...
    I have never really used Powershell scripts - as Powershell requires .Net Framework
    Which adding them both makes WinPE heavy...
    But, Thanks To You and your great help with this App - I may not be able to Write the code
    But I now have a better understanding of it and I can at least Follow it...

    Guess all that is left is the - search function for a drive "flag" and the drive letter assignment...
    I know how to do it in cmd... Just not in PS
      My Computer


  5. Posts : 3,453
       #35

    Kyhi said:
    I figured them both out...
    I have never really used Powershell scripts - as Powershell requires .Net Framework
    Which adding them both makes WinPE heavy...
    But, Thanks To You and your great help with this App - I may not be able to Write the code
    But I now have a better understanding of it and I can at least Follow it...

    Guess all that is left is the - search function for a drive "flag" and the drive letter assignment...
    I know how to do it in cmd... Just not in PS
    Cool!

    The USB drive search can be done here:
    Code:
    ....
    foreach ($Drive in $Drives){    
    
    if (Test-Path(Join-Path $Drive.Root -ChildPath "CDUsb.y")) {$USBDrive = $Drive.Root}    
    
    $HivePath = Join-Path($Drive.Root) -ChildPath "Windows\System32\config\SOFTWARE"      
    
     if (Test-Path($HivePath))
    ...
    Then set here:

    Code:
    ...
    $SaveToList = @()
    
    #Saving to System drive instead of Desktop
    $Destination = Join-Path $env:SystemDrive -ChildPath "\HostDrivers"
    
    $SaveToList += $Destination
    
    #Add USB drive to list
    if($USBDrive -ne '') {$SaveToList += Join-Path $USBDrive -ChildPath "HostDrivers"}
    
    $DriverReport = Join-Path ([Environment]::GetFolderPath("Desktop")) -ChildPath "Driver Integration Report.txt"
    
    ...
    I'll update the script with this logic when I get home tonite. But give it a go
      My Computer


  6. Posts : 4,143
    Windows 3.1 to Windows 11
    Thread Starter
       #36

    This App Is Exactly and Perfectly What We Needed....
    I Sincerely Owe You One For Taking The Time To Help...

    Process in Pictures
    App Development Help-screenshot00002.jpg
    App Development Help-screenshot00003.jpg
    App Development Help-screenshot00004.jpg
    App Development Help-screenshot00005.jpg

    Final Revisions
    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     : Kyhi
        Version    : 1.0.0.8 
    #> 
    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 = 80 
    $size.Height = 30
    $console.WindowSize = $size
    $console.WindowTitle ='WinPE Driver Integration'
    Write-Host "Search For Matching OS Drivers"
    Write-Host ""
    $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(Join-Path $Drive.Root -ChildPath "MyDrive.Tag")) {$USBDrive = $Drive.Root}    
        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 ($env:SystemDrive) -ChildPath "HostDrivers-Ram"
    $SaveToList += $Destination
    if(Test-Path("Y:\CDUsb.y")){$SaveToList += Join-Path ("Y:\") -ChildPath "HostDrivers-CDUsb"}
    if($USBDrive -ne '') {$SaveToList += Join-Path $USBDrive -ChildPath "HostDrivers-MyDrive"}
    $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())) {
                $SaveToList += Join-Path ($Item) -ChildPath "HostDrivers-OS"
            Break
            }
        }
        Write-Host ""
        Write-Host ""
        foreach($Item1 in $SaveToList) { Write-Host $Item1 }
        $Drive2 = Read-Host "Select Drive Letter Destination For Exported HostDrivers Folder"
     
        foreach($Item1 in $SaveToList){
                if ($Drive2 -ne '' -and $Item1.StartsWith($Drive2.ToUpper())) {
                    $Destination = $Item1
                Break
            }
        }
        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 ""
            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
            Write-Host ""
            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 
            Write-Host ""
            if ((Test-Path ($Destination)) -and (Read-Host "Do You Want To Delete The $Destination Folder? Y/N") -eq 'y') {Remove-Item $Destination -Recurse}
            Write-Host ""
            if ((Test-Path ($DriverReport)) -and (Read-Host "Do You Want To Delete The Drivers Integration Report? Y/N")  -eq 'y') {Remove-Item $DriverReport}
            Write-Host ""
            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 Matching OS Drivers To Export"}
    Write-Host ""
    Write-Host "Done"
    Read-Host
      My Computer


  7. Posts : 3,453
       #37

    Kyhi said:
    This App Is Exactly and Perfectly What We Needed....
    I Sincerely Owe You One For Taking The Time To Help...

    Process in Pictures
    App Development Help-screenshot00002.jpg
    App Development Help-screenshot00003.jpg
    App Development Help-screenshot00004.jpg
    App Development Help-screenshot00005.jpg

    Final Revisions
    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     : Kyhi
        Version    : 1.0.0.8 
    #> 
    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 = 80 
    $size.Height = 30
    $console.WindowSize = $size
    $console.WindowTitle ='WinPE Driver Integration'
    Write-Host "Search For Matching OS Drivers"
    Write-Host ""
    $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(Join-Path $Drive.Root -ChildPath "MyDrive.Tag")) {$USBDrive = $Drive.Root}    
        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 ($env:SystemDrive) -ChildPath "HostDrivers-Ram"
    $SaveToList += $Destination
    if(Test-Path("Y:\CDUsb.y")){$SaveToList += Join-Path ("Y:\") -ChildPath "HostDrivers-CDUsb"}
    if($USBDrive -ne '') {$SaveToList += Join-Path $USBDrive -ChildPath "HostDrivers-MyDrive"}
    $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())) {
                $SaveToList += Join-Path ($Item) -ChildPath "HostDrivers-OS"
            Break
            }
        }
        Write-Host ""
        Write-Host ""
        foreach($Item1 in $SaveToList) { Write-Host $Item1 }
        $Drive2 = Read-Host "Select Drive Letter Destination For Exported HostDrivers Folder"
     
        foreach($Item1 in $SaveToList){
                if ($Drive2 -ne '' -and $Item1.StartsWith($Drive2.ToUpper())) {
                    $Destination = $Item1
                Break
            }
        }
        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 ""
            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
            Write-Host ""
            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 
            Write-Host ""
            if ((Test-Path ($Destination)) -and (Read-Host "Do You Want To Delete The $Destination Folder? Y/N") -eq 'y') {Remove-Item $Destination -Recurse}
            Write-Host ""
            if ((Test-Path ($DriverReport)) -and (Read-Host "Do You Want To Delete The Drivers Integration Report? Y/N")  -eq 'y') {Remove-Item $DriverReport}
            Write-Host ""
            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 Matching OS Drivers To Export"}
    Write-Host ""
    Write-Host "Done"
    Read-Host
    Well done Mr Bond, glad to be of assistance ; )
      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 08:46.
Find Us




Windows 10 Forums