Example of how to install a inf file:
NB You can also use the dism module cmdlets (e.g. Add-WindowsDriver).
function Install-Driver($path) {
# trust the driver certificate.
$catPath = $path.Replace('.inf', '.cat')
$cerPath = $path.Replace('.inf', '.cer')
$certificate = (Get-AuthenticodeSignature $catPath).SignerCertificate
[System.IO.File]::WriteAllBytes($cerPath, $certificate.Export('Cert'))
Import-Certificate -CertStoreLocation Cert:\LocalMachine\TrustedPublisher $cerPath | Out-Null
# install the driver.
pnputil -i -a $path
if ($LASTEXITCODE) {
throw "Failed with exit code $LASTEXITCODE"
}
}
[IO.Compression.ZipFile]::ExtractToDirectory('C:\Windows\Temp\virtio\virtio.zip', 'C:\Windows\Temp\virtio')
$virtioDestinationDirectory = "$env:ProgramFiles\virtio"
Get-ChildItem -Recurse -File C:\Windows\Temp\virtio\drivers.tmp | ForEach-Object {
$driverName = $_.Directory.Parent.Parent.Name
$driverSourceDirectory = $_.Directory
$driverDestinationDirectory = "$virtioDestinationDirectory\$driverName"
if (Test-Path $driverDestinationDirectory) {
return
}
Write-Host "Installing the $driverName driver..."
mkdir -Force $driverDestinationDirectory | Out-Null
Copy-Item "$driverSourceDirectory\*" $driverDestinationDirectory
Install-Driver (Resolve-Path "$driverDestinationDirectory\*.inf").Path
}
Write-Host 'Installing the Balloon service...'
&"$virtioDestinationDirectory\Balloon\blnsvr.exe" -i