Added screenshot.ps1 and screenshots.ps1

This commit is contained in:
Markus Fleschutz 2020-10-03 21:26:33 +00:00
parent 3630624c23
commit da51bdb0fc
3 changed files with 194 additions and 0 deletions

View File

@ -18,6 +18,8 @@ PowerShell Scripts Included
* [poweroff.ps1](Scripts/poweroff.ps1) - halts the local computer, administrator rights might be needed
* [news.ps1](Scripts/news.ps1) - prints the latest news
* [reboot.ps1](Scripts/reboot.ps1) - reboots the local computer, administrator rights might be needed
* [screenshot.ps1](Scripts/screenshot.ps1) - takes a single screenshot
* [screenshots.ps1](Scripts/screenshots.ps1) - takes multiple screenshots
* [SHA1.ps1](Scripts/SHA1.ps1) - prints the SHA1 checksum of the given file
* [SHA256.ps1](Scripts/SHA256.ps1) - prints the SHA256 checksum of the given file
* [speak.ps1](Scripts/speak.ps1) - speaks the given text by text-to-speech (TTS)

96
Scripts/screenshot.ps1 Normal file
View File

@ -0,0 +1,96 @@
Function Get-TimedScreenshot {
<#
.SYNOPSIS
Get-TimedScreenshot
.DESCRIPTION
A function that takes screenshots and saves them to a folder.
.PARAMETER $Path
Specifies the folder path.
.PARAMETER $Interval
Specifies the interval in seconds between taking screenshots.
.PARAMETER $EndTime
Specifies when the script should stop running in the format HH-MM
.EXAMPLE
PS C:\> Get-TimedScreenshot -Path c:\temp\ -Interval 30 -EndTime 14:00
.LINK
http://obscuresecurity.blogspot.com/2013/01/Get-TimedScreenshot.html
https://github.com/obscuresec/random/blob/master/Get-TimedScreenshot
#>
[CmdletBinding()] Param(
[Parameter(Mandatory=$True)]
[ValidateScript({Test-Path -Path $_ })]
[string] $Path,
[Parameter(Mandatory=$True)]
[int32] $Interval,
[Parameter(Mandatory=$True)]
[string] $EndTime
)
#Define helper function that generates and saves screenshot
Function GenScreenshot {
$ScreenBounds = [Windows.Forms.SystemInformation]::VirtualScreen
$ScreenshotObject = New-Object Drawing.Bitmap $ScreenBounds.Width, $ScreenBounds.Height
$DrawingGraphics = [Drawing.Graphics]::FromImage($ScreenshotObject)
$DrawingGraphics.CopyFromScreen( $ScreenBounds.Location, [Drawing.Point]::Empty, $ScreenBounds.Size)
$DrawingGraphics.Dispose()
$ScreenshotObject.Save($FilePath)
$ScreenshotObject.Dispose()
}
Try {
#load required assembly
Add-Type -Assembly System.Windows.Forms
Do {
#get the current time and build the filename from it
$Time = (Get-Date)
[string] $FileName = "$($Time.Month)"
$FileName += '-'
$FileName += "$($Time.Day)"
$FileName += '-'
$FileName += "$($Time.Year)"
$FileName += '-'
$FileName += "$($Time.Hour)"
$FileName += '-'
$FileName += "$($Time.Minute)"
$FileName += '-'
$FileName += "$($Time.Second)"
$FileName += '.png'
#use join-path to add path to filename
[string] $FilePath = (Join-Path $Path $FileName)
#run screenshot function
GenScreenshot
Write-Verbose "Saved screenshot to $FilePath. Sleeping for $Interval seconds"
Start-Sleep -Seconds $Interval
}
#note that this will run once regardless if the specified time as passed
While ((Get-Date -Format HH:%m) -lt $EndTime)
}
Catch {Write-Warning "$Error[0].ToString() + $Error[0].InvocationInfo.PositionMessage"}
}

96
Scripts/screenshots.ps1 Normal file
View File

@ -0,0 +1,96 @@
Function Get-TimedScreenshot {
<#
.SYNOPSIS
Get-TimedScreenshot
.DESCRIPTION
A function that takes screenshots and saves them to a folder.
.PARAMETER $Path
Specifies the folder path.
.PARAMETER $Interval
Specifies the interval in seconds between taking screenshots.
.PARAMETER $EndTime
Specifies when the script should stop running in the format HH-MM
.EXAMPLE
PS C:\> Get-TimedScreenshot -Path c:\temp\ -Interval 30 -EndTime 14:00
.LINK
http://obscuresecurity.blogspot.com/2013/01/Get-TimedScreenshot.html
https://github.com/obscuresec/random/blob/master/Get-TimedScreenshot
#>
[CmdletBinding()] Param(
[Parameter(Mandatory=$True)]
[ValidateScript({Test-Path -Path $_ })]
[string] $Path,
[Parameter(Mandatory=$True)]
[int32] $Interval,
[Parameter(Mandatory=$True)]
[string] $EndTime
)
#Define helper function that generates and saves screenshot
Function GenScreenshot {
$ScreenBounds = [Windows.Forms.SystemInformation]::VirtualScreen
$ScreenshotObject = New-Object Drawing.Bitmap $ScreenBounds.Width, $ScreenBounds.Height
$DrawingGraphics = [Drawing.Graphics]::FromImage($ScreenshotObject)
$DrawingGraphics.CopyFromScreen( $ScreenBounds.Location, [Drawing.Point]::Empty, $ScreenBounds.Size)
$DrawingGraphics.Dispose()
$ScreenshotObject.Save($FilePath)
$ScreenshotObject.Dispose()
}
Try {
#load required assembly
Add-Type -Assembly System.Windows.Forms
Do {
#get the current time and build the filename from it
$Time = (Get-Date)
[string] $FileName = "$($Time.Month)"
$FileName += '-'
$FileName += "$($Time.Day)"
$FileName += '-'
$FileName += "$($Time.Year)"
$FileName += '-'
$FileName += "$($Time.Hour)"
$FileName += '-'
$FileName += "$($Time.Minute)"
$FileName += '-'
$FileName += "$($Time.Second)"
$FileName += '.png'
#use join-path to add path to filename
[string] $FilePath = (Join-Path $Path $FileName)
#run screenshot function
GenScreenshot
Write-Verbose "Saved screenshot to $FilePath. Sleeping for $Interval seconds"
Start-Sleep -Seconds $Interval
}
#note that this will run once regardless if the specified time as passed
While ((Get-Date -Format HH:%m) -lt $EndTime)
}
Catch {Write-Warning "$Error[0].ToString() + $Error[0].InvocationInfo.PositionMessage"}
}