When managing devices in a Windows environment, automating driver installation can simplify the process, especially when dealing with numerous drivers. PowerShell provides an efficient way to automate driver installation with just a few lines of code. This method is particularly useful when deploying driver packs via Microsoft Endpoint Configuration Manager (MECM) or Intune, allowing administrators to streamline and automate the driver deployment process.
In this article, we will guide you through how to automate driver installation with PowerShell, enabling you to efficiently manage and deploy drivers from a specified directory.
Prerequisites
Before we start, make sure you have:
- Administrator privileges on the computer.
- The driver files (.inf format) available in a folder on your system.
Manufacturer Driver Pack Catalogs
Here are some links to popular driver pack catalogs from major manufacturers. These catalogs provide pre-packaged drivers that can be used for automated deployments in enterprise environments:
The PowerShell Script
Below is a PowerShell script that installs all the drivers from a specified directory and its subdirectories:
# Get all drivers in the current directory and subdirectories
$driversPath = "C:\Drivers"
$drivers = Get-ChildItem -Path $driversPath -Recurse -Filter "*.inf"
# Install all drivers
if ($drivers.count -ge "0") {
Write-Warning "$($drivers.count) drivers found!"
foreach ($driver in $drivers) {
try {
Write-Host "Installing driver $($driver.FullName) ..."
pnputil.exe -i -a $driver.FullName
Write-Host "Driver installed successfully."
}
catch {
Write-Error "Error while installing driver $($driver.FullName): $($_.Exception.Message)"
}
}
Write-Warning "Process completed! Restart your computer to apply changes."
}
else {
Write-Warning "No drivers found!"
}
Step-by-Step Breakdown
- Define the path to your drivers:
The$driversPath
variable stores the location of your drivers. In this example, the path is set toC:\Drivers
. You can modify this to point to any folder where your drivers are stored. - Retrieve the drivers:
TheGet-ChildItem
cmdlet is used to search for all.inf
files in the specified directory and its subdirectories. These.inf
files contain the information needed to install the drivers. - Install the drivers:
For each driver file found, the script uses thepnputil.exe
command to install the driver. If the installation is successful, a message is printed to the console. If an error occurs, the script catches the exception and displays an error message. - Completion message and restart reminder:
Once all drivers are installed, the script outputs a completion message and reminds the user to restart the computer to apply the changes.
Useful for MECM or Intune Deployment
This method can be particularly valuable when deploying driver packs through tools like Microsoft Endpoint Configuration Manager (MECM) or Intune. By automating the driver installation process, you can ensure that the correct drivers are installed across multiple devices during deployment, reducing manual work and the risk of errors.
These links will provide access to the latest drivers, ensuring that you are deploying the most up-to-date drivers for your devices.
Conclusion
With this PowerShell script, you can easily install multiple drivers at once without having to go through each one manually. This is especially helpful when setting up new machines or when a large number of drivers need to be installed. When combined with MECM or Intune, this method offers a robust and scalable solution for deploying drivers across your organization.
By automating the driver installation process, you save time and reduce the chances of errors.