Not possible with the code you say that you are using.
$File = "E:\temp\myscreenshot.bmp"
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
# Gather Screen resolution information
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
# .. monitor width in pixels..
$Width = [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Width
# .. monitor height in pixels..
$Height = [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Height
# .. Capture points
$Left = 0 # ..monitor starting left pixel..
$Top = 0 # ..monitor starting top pixel, normally zero..
Poor man's debug - using variable squeezing to assign and screen output results
Remove the edge parens before delivery
# Create bitmap using the top-left and bottom-right bounds
($bitmap = New-Object System.Drawing.Bitmap $Width, $Height)
# Create Graphics object
($graphic = [System.Drawing.Graphics]::FromImage($bitmap))
# Capture screen
($graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size))
# Save to file
$bitmap.Save($File)
You will note, that nothing physical / file system related, via the above output gives you anything you can grab for your use case.
Of course, you can use the code as it, increment the image file name, do the compare and decide which it delete.
The FileSystem cmdlets (like... Get-FileHash, etc...), means you are working on a serialized file.
Get-FileHash
Module:Microsoft.PowerShell.Utility
Computes the hash value for a file by using a specified hash
algorithm.
Update for OP
Personally, I've never tried, and not ever had a use case where it was ever needed. So, it's a concept, but possible, it's all speculation at this point relative to all I understand. Especially hashing and serializing that after doing whatever you plan to do with it. Filesystem cmdlets will only work on the file system by design.
As for putting the stuff in the buffer. I direct you to Trevor Sullivan's blog post here, where he demos initializing a byte array in PowerShell.
Sometimes you’ll need to initialize a new buffer as an array of bytes.
For example, if you want to generate random data using the NextBytes()
method on the System.Random class, you need to pass in a byte array
buffer for the method to write to. Creating a byte array in PowerShell
may not be immediately obvious.