Moving a hard drive to new hardware Print

  • 0

Here's a PowerShell script that resets Windows drivers after moving a hard drive to new hardware. It forces Windows to detect and install the correct drivers by removing non-present devices and resetting the Plug and Play (PnP) configuration.

 
# Run this script as Administrator Write-Host "Resetting Windows drivers for new hardware..." # Remove all non-present devices Write-Host "Removing non-present devices..." $NonPresentDevices = Get-PnpDevice | Where-Object { $_.Status -eq "Unknown" -or $_.Status -eq "Error" } foreach ($device in $NonPresentDevices) { Write-Host "Removing: $($device.FriendlyName)" pnputil /remove-device $device.InstanceId } # Reset the Plug and Play configuration Write-Host "Resetting Plug and Play configuration..." pnputil /scan-devices # Refresh the device manager Write-Host "Refreshing Device Manager..." Start-Process "devmgmt.msc" -ArgumentList "/refresh" # Restart Windows to apply changes $choice = Read-Host "Do you want to restart the computer now? (Y/N)" if ($choice -match "^[Yy]$") { Write-Host "Restarting in 10 seconds..." Start-Sleep -Seconds 10 Restart-Computer -Force } else { Write-Host "Please restart your computer manually to complete the process." } Write-Host "Driver reset process completed."

How It Works:

  1. Removes Non-Present Devices – Uninstalls ghost devices from the previous hardware.

  2. Rescans for Devices – Forces Windows to detect new hardware and install appropriate drivers.

  3. Refreshes Device Manager – Ensures immediate application of changes.

  4. Restart Prompt – Gives the user an option to restart for a full reset.

Run the script as an Administrator after moving the hard drive to new hardware.


Was this answer helpful?

« Back

Powered by WHMCompleteSolution