Screengrab from all computers on a network

zorgan

Thread Starter
Joined
Aug 2, 2007
Messages
239
Using powershell, can anyone think of a way to grab screen grabs of the current state of every single computer on a network?

is this even possible?

I know if you hit the PrintScn button you can capture onto the clipboard what is currently on the screen, this information is buffered on the clipboard I believe, I have tested by loading up paint.exe and pasting in there afterwards, I wonder if that information can be grabbed to a folder on one computer that I run the script from that can put all the jpg into one folder?
 
Joined
Sep 21, 2007
Messages
11,983
Are you a hacker or something? Why would you want to invade the privacy of all of your PC users?
 

zorgan

Thread Starter
Joined
Aug 2, 2007
Messages
239
haha no, lunarlander, this is for checking a bunch of computers on a workgroup they all belong to me! lol

Your reply however really made my day! hahahah
 
Joined
Jan 8, 2016
Messages
286
First Name
Dave
Hey zorgan,

Yes this is definately possible.

There are many ways to can approach it, you could send keys to the shell such as the print screen key and then save the contents of the clipboard to a file. However this has the ability to fail and isn't completely reliable.

That leaves using .NET Framework to do all of the heavy work. Anything that is do able in the .NET framework is do able in powershell due to its ability to parse and execute C# code.

Rather than reinventing the wheel, we can add a function written by someone else and just call it on our powershell script.
https://gallery.technet.microsoft.com/scriptcenter/eeff544a-f690-4f6b-a586-11eea6fc5eb8

Downloading and saving that .ps1 script contains the function require to capture the whole screen or individual windows. Open up the file in notepad and copy the contents into Powershell ISE.

You can then use it in your powershell script like so:



You should be able to get this to remotely execute on PC's on your network and get them to all save in one network location. You can also make the name of the file in the path change dynamically if it contains the computer name it is executing on like so:



If you need help with remote execution on PC's let me know. Unfortunately I don't have access to a fleet of 1500 PC's to test on anymore, but I should be able to dig up some old scripts to use as a reference.
 

zorgan

Thread Starter
Joined
Aug 2, 2007
Messages
239
Okay So I have tested and if I run on the one computer it works!

I put
Code:
\\COMPUTER001\USER\DESKTOP\SCREENGRAB\
as the destination for the screenshot and it appeared on computer001 on the desktop, the problem I have now is how to get this running network wide on COMPUTER001,COMPUTER002,COMPUTER003 etc and for the files all to reside on COMPUTER001 desktop?

I have also been investigating various methods.

Using the snipping tool but I don't think this is an option as it may only work on the desktop and if a full screen application is running it may not work.
 
Joined
Jan 8, 2016
Messages
286
First Name
Dave
Ah this is annoying, I can't find any of the script I made from when I use to do this all the time. No matter, I can figure it out again, however I won't be able to test it easily on my end.

First of all, on the machine you will be running the script from, e.g. a server logged in as a Domain Administrator account you will want to create a text document with a list of all of the DNS names or IP addresses of the PC's, one per line.

Code:
COMPUTER001
COMPUTER002
COMPUTER003
etc...
Then in our script to import the list of computers we do:
Code:
$Path = #Replace this with the path to the text file in string format.
$Computers = Get-Content -Path $Path

foreach($Computer in $Computers){
Write-Host "This is $Computer"
}
The Write-Host lines is just to confirm that the script has successfully imported the list of computers. If it has we can replace everything in the foreach loop with what we want to execute on each PC.

To start off with, we need to open a remote powershell session to the respective PC. It is important to note that some specific settings may be required to be set on the recipient PC. However as I don't readily have access to all of the PC's I had in my previous employment, you will have to give it a go and let me know if you get any errors in the console.
To open the remote session, inside the foreach loop, enter the following code:


Code:
foreach($Computer in $Computers){
$Session = New-PSSession -ComputerName $Computer
 Enter-PSSession $Session

 #Paste in the block of code you wish to execute on each PC here

 #code block end
 Exit-PSSession
 Remove-PSSession $Session
}
It is worth mentioning that this is a synchronous method of doing things, meaning it will execute the code on a PC and wont execute it on any others until the current PC has completed the task, so if you have a large amount of computers you will be executing this on, it is recommended to use an asynchronous method meaning it will execute the code on many PC's simultaneously which is much faster on larger environments.

For this, you will still need the text document we created above but you can use the following code:
Code:
$path = #Network path to dump screenshots as in previous post (including the environmental variable computer name)
$s = New-PSSession -ComputerName (Get-Content Computers.txt) -Credential Domain01\Admin01 -ThrottleLimit 16
Invoke-Command -Session $s -ScriptBlock {Take-Screenshot -screen -file $path -imagetype jpeg} -AsJob
I should mention, I've never tried this last way of doing this before but it is based on an example from:
https://docs.microsoft.com/en-us/po...wershell.core/new-pssession?view=powershell-7

So it should work fine. You will also need to change the credentials in the credential argument.
 

zorgan

Thread Starter
Joined
Aug 2, 2007
Messages
239
Does this apply if the computers are not on a domain? The computers have a main computer but it's just Windows 10 Pro and not on a domain.
 
Joined
Jan 8, 2016
Messages
286
First Name
Dave
So, for each PC, you need an account you can use that has permissions to execute powershell scripts on said PC. In most corporate environments including SMEs the computers are all linked under a domain that allows them to share user accounts. If this is not the case, you can either create some kind of "switch case" statement or "if then else" statement to provide the admin credentials per machine (Unless all of the computers share an admin account with the same credentials that has been manually set up on them).

The code to do this would look something like:
Code:
$Password = convertto-securestring -AsPlainText -Force -String "Password"
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "UserName",$Password
$Session = New-PSSession -ComputerName $Computer -Credential $Credentials
...
A switch case statement takes a switch (a variable) and carrys out an operation based on the value of that switch. For example:
Code:
$Computer = "COMPUTER001"
$value = 0
switch ($Computer){
    "COMPUTER001"{
       $value = 1
    }
    Default {
        $value = 2
    }

}

write-host $value
You can play around with the computer variable string to see how it effects the value variable. You can also add you own conditions by following the same format, making sure you leave the "Default" case as the last case. Switch Cases are a more complex, but neater way of doing quick if statements where there are a lot of potential outputs such as different credentials for each computer in a list of computers.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top