You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, everyone, I hope you all are doing fantastic.
I originally posted this on Issues, but @ruxunderscore instructed me to post this here so more people would see it.
After watching @ChrisTitusTech's video on drivers, I wondered if there's a way to install multiple drivers at once after reloading my system. Finding no way to do so without using 3rd-party software or installing one by one in Device Manager, I decided to create a simple PowerShell script that does this process, using the .inf files in a folder specified by the user.
I'm not at all familiar with PowerShell programming (I asked ChatGPT for help), but the end result looks pretty solid (for a starting point).
Some parts of the script are commented out. The reason is that they didn't work as expected and I lack the knowledge to fix them. I'm sure some people here will make A LOT of improvements to this (maybe a better version will be added to MicroWin?).
What isn't working yet?
1- The script doesn't accept paths with spaces, even with single or double quotes;
2- The script doesn't show a list of drivers that failed to install, if that happens, nor does it show the error messages that pnputil.exe might give;
Feel free to add more features that you may come up with, I hope this evolves and becomes a tool with the same quality as WinUtil itself :)
Here is the code:
Write-Host "Automatic Driver Install Script"
Write-Host "Version: 1.0.0"
Write-Host ""
# Check if the script is running as administrator
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "This script needs to be run as an administrator." -ForegroundColor Red
Write-Host "Please open an elevated PowerShell prompt and try again." -ForegroundColor Red
Exit
}
# Prompt the user to input the path to the drivers folder
do {
$driverFolderPath = Read-Host "Enter the path to the drivers folder (e.g., 'C:\Users\Admin\Drivers')"
# Verify that the specified folder exists
if (-not (Test-Path $driverFolderPath)) {
Write-Host "The specified folder does not exist." -ForegroundColor Red
Write-Host "Please make sure you entered the correct path." -ForegroundColor Red
} else {
# Get a list of driver files in the folder
$driverFiles = Get-ChildItem -Path $driverFolderPath -Recurse -Include *.inf
# Check if any driver files were found
if ($driverFiles.Count -eq 0) {
Write-Host "No driver files (.inf) were found in the specified folder." -ForegroundColor Red
Write-Host "Please make sure you entered the correct path." -ForegroundColor Red
}
}
} until ((Test-Path $driverFolderPath) -and ($driverFiles.Count -gt 0))
# Display a message indicating the number of driver files found
Write-Host "$($driverFiles.Count) driver files were found in the specified folder." -ForegroundColor Green
# Initialize progress variables
$totalFiles = $driverFiles.Count
$currentFileIndex = 0
$failedDrivers = @()
$alreadyInstalledDrivers = @()
# Loop through each driver file and install it
foreach ($driverFile in $driverFiles) {
# Increment current file index
$currentFileIndex++
# Calculate progress percentage
$progressPercentage = [Math]::Round(($currentFileIndex / $totalFiles) * 100)
# Display progress bar
Write-Progress -Activity "Installing Drivers" -Status "Progress: $progressPercentage%" -PercentComplete $progressPercentage
# Install the driver using the pnputil command
$installResult = pnputil.exe /add-driver $driverFile.FullName /install 2>&1
<#
if ($LASTEXITCODE -eq 0) {
# Driver installed successfully
continue
} elseif ($installResult -match "The driver package (.+) is already installed") {
# Driver is already installed
$driverName = $Matches[1]
$alreadyInstalledDrivers += $driverName
} else {
# Driver installation failed
$failedDrivers += @{
Driver = $driverFile.Name
Error = $installResult
}
}
#>
}
# Display installation results
Write-Host "Installation completed." -ForegroundColor Green
<#
if ($failedDrivers.Count -gt 0) {
Write-Host "The following drivers failed to install:" -ForegroundColor Red
foreach ($failedDriver in $failedDrivers) {
Write-Host "Driver: $($failedDriver.Driver)" -ForegroundColor Red
Write-Host "Error: $($failedDriver.Error)" -ForegroundColor Red
Write-Host "------------------------"
}
} else {
Write-Host "All drivers have been successfully installed." -ForegroundColor Green
}
if ($alreadyInstalledDrivers.Count -gt 0) {
Write-Host "The following drivers were already installed:" -ForegroundColor Yellow
foreach ($driverName in $alreadyInstalledDrivers) {
Write-Host "Driver: $driverName" -ForegroundColor Yellow
Write-Host "------------------------"
}
}
#>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, everyone, I hope you all are doing fantastic.
I originally posted this on Issues, but @ruxunderscore instructed me to post this here so more people would see it.
After watching @ChrisTitusTech's video on drivers, I wondered if there's a way to install multiple drivers at once after reloading my system. Finding no way to do so without using 3rd-party software or installing one by one in Device Manager, I decided to create a simple PowerShell script that does this process, using the .inf files in a folder specified by the user.
I'm not at all familiar with PowerShell programming (I asked ChatGPT for help), but the end result looks pretty solid (for a starting point).
Some parts of the script are commented out. The reason is that they didn't work as expected and I lack the knowledge to fix them. I'm sure some people here will make A LOT of improvements to this (maybe a better version will be added to MicroWin?).
What isn't working yet?
1- The script doesn't accept paths with spaces, even with single or double quotes;
2- The script doesn't show a list of drivers that failed to install, if that happens, nor does it show the error messages that pnputil.exe might give;
Feel free to add more features that you may come up with, I hope this evolves and becomes a tool with the same quality as WinUtil itself :)
Here is the code:
Beta Was this translation helpful? Give feedback.
All reactions