Skip to content

Instantly share code, notes, and snippets.

@scriptjunkie
Created June 25, 2025 21:59
Show Gist options
  • Save scriptjunkie/12bc05bd3cdd46eb2655e559fc2a74f3 to your computer and use it in GitHub Desktop.
Save scriptjunkie/12bc05bd3cdd46eb2655e559fc2a74f3 to your computer and use it in GitHub Desktop.
PowerShell script to scan to your desktop
$deviceManager = new-object -ComObject WIA.DeviceManager
$device = $deviceManager.DeviceInfos.Item(1).Connect()
$wiaFormatPNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
foreach ($item in $device.Items) {
$image = $item.Transfer($wiaFormatPNG)
if($image.FormatID -ne $wiaFormatPNG)
{
$imageProcess = new-object -ComObject WIA.ImageProcess
$imageProcess.Filters.Add($imageProcess.FilterInfos.Item("Convert").FilterID)
$imageProcess.Filters.Item(1).Properties.Item("FormatID").Value = $wiaFormatPNG
$image = $imageProcess.Apply($image)
}
$i = 1
while (test-path ("$env:userprofile\desktop\scan$i.png" ) ) { $i += 1 }
$image.SaveFile("$env:userprofile\desktop\scan$i.png")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment