Skip to content

Instantly share code, notes, and snippets.

@cleytonferrari
Created September 9, 2022 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleytonferrari/f716ded1065ca96933f742b13c064956 to your computer and use it in GitHub Desktop.
Save cleytonferrari/f716ded1065ca96933f742b13c064956 to your computer and use it in GitHub Desktop.
Salva print via powershell
#Salva print via Powershell
#Maiores informações https://stackoverflow.com/questions/2969321/how-can-i-do-a-screen-capture-in-windows-powershell/2970339#2970339
#Para usar: > .\print.ps1 "C:\Users\Cleyton Ferrari\Downloads\"
Param(
[string]$path
)
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
function screenshot($path)
{
$width = 0;
$height = 0;
$workingAreaX = 0;
$workingAreaY = 0;
$fileName = get-date -uformat "\%d-%m-%Y_%H-%M-%S.png";
$screen = [System.Windows.Forms.Screen]::AllScreens;
foreach ($item in $screen)
{
if($workingAreaX -gt $item.WorkingArea.X)
{
$workingAreaX = $item.WorkingArea.X;
}
if($workingAreaY -gt $item.WorkingArea.Y)
{
$workingAreaY = $item.WorkingArea.Y;
}
$width = $width + $item.Bounds.Width;
if($item.Bounds.Height -gt $height)
{
$height = $item.Bounds.Height;
}
}
$bounds = [Drawing.Rectangle]::FromLTRB($workingAreaX, $workingAreaY, $width, $height);
$bmp = New-Object Drawing.Bitmap $width, $height;
$graphics = [Drawing.Graphics]::FromImage($bmp);
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size);
$bmp.Save($path+$fileName);
$graphics.Dispose();
$bmp.Dispose();
}
screenshot $path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment