How to install a Null Printer and take screenshot of the Devices and Printers

Hi All,
Been lately caught up with a few issues and could not get time to go through the posts here.
I would need help on some scripts. Any help will be highly appreciated.

I need to install a printer by calling a cmd file from a location.
Once the printer is installed I need to capture the image of the Devices and Printers section from the control panel.

The script that I have now is
#to call the batch file
Start-Process -FilePath E:\NullPrinter.cmd -Wait -passthru;$a.ExitCode

To take screenshot

function screenshot([Drawing.Rectangle]$bounds, $path) {
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
$graphics = [Drawing.Graphics]::FromImage($bmp)

$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)

$bmp.Save($path)

$graphics.Dispose()
$bmp.Dispose()
}

The above script isnt working. Can someone please help?

And it won’t, that is by design.

To take a screen shot you have to be logged on the system as an interactive user.

This is not possible with PoSH as PoSH provided no way for you to logon to a remote computer, like you’d do with RDP or other remote viewer tools. It’s a Windows security boundary, only one person can be logged on interactively at a time. PoSH will not allow you to violate this specification.

If you need to logon to a remote system in the context of another user that that is what MS SysInternals ‘psexec’, or tools like AuotIT are for.

Think about the implications of what you are asking here. Being able to remote view a system without the users direct consent.
Popping UI screens (so you can screen shoot it) on a currently logged in user, like malware, spyware.

Why the need to take a screen shot, when you can user WMI/CIM to pull these settings?

If you are an admin on the remote host, you can pull any information you choose, well, as long as PSRemoting is enabled and settings are properly applied. Yet, again, no, screen shooting, is not a thing in what you are after, nor should it be.

Use PoSH to remote install printers (there is plenty of sample code on the web to show how to do that, powershellgallery.com, the MS scriptingguys blog, etc.), then use PoSH remoting to pull other setting information after the install (again, lot’s of sample code on the web showing how to do this).

This is a local printer ans I would need a screenshot of the installed printers in the control panel list.
The script that I have takes the screenshot of the ISE window from where I am running the script.
Please assist