This PowerShell script will create a screenshot file named MyScreenshot.bmp.
I created a folder named temp and I put this PowerShell script named screen.ps1.
The source code of this script is this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | $File = "MyScreenshot.bmp" Add-Type -AssemblyName System.Windows.Forms Add-type -AssemblyName System.Drawing # Gather Screen resolution information $Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen $Width = $Screen.Width $Height = $Screen.Height $Left = $Screen.Left $Top = $Screen.Top # 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) Write-Output "Screenshot saved to:" Write-Output $File |
To run this script you need to be allowed with this args:
1 2 3 | PS C:\temp> powershell.exe -executionpolicy bypass -file .\screen.ps1 Screenshot saved to: MyScreenshot.bmp |