mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-23 21:20:51 +01:00
Update save-screenshot.ps1
This commit is contained in:
parent
a69e3c3bc1
commit
e6f49215f0
@ -3,8 +3,8 @@
|
|||||||
Saves a single screenshot
|
Saves a single screenshot
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This script takes a single screenshot and saves it into a target folder (the user's pictures folder by default).
|
This script takes a single screenshot and saves it into a target folder (the user's pictures folder by default).
|
||||||
.PARAMETER Directory
|
.PARAMETER TargetFolder
|
||||||
Specifies the target directory (the user's pictures folder by default)
|
Specifies the target folder (the user's pictures folder by default)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./save-screenshot
|
PS> ./save-screenshot
|
||||||
✔️ screenshot saved to C:\Users\Markus\Pictures\2021-10-10T14-33-22.png
|
✔️ screenshot saved to C:\Users\Markus\Pictures\2021-10-10T14-33-22.png
|
||||||
@ -14,7 +14,7 @@
|
|||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$Directory = "$HOME/Pictures")
|
param([string]$TargetFolder = "$HOME/Pictures")
|
||||||
|
|
||||||
function TakeScreenshot { param([string]$FilePath)
|
function TakeScreenshot { param([string]$FilePath)
|
||||||
Add-Type -Assembly System.Windows.Forms
|
Add-Type -Assembly System.Windows.Forms
|
||||||
@ -28,12 +28,12 @@ function TakeScreenshot { param([string]$FilePath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (-not(test-path "$Directory" -pathType container)) {
|
if (-not(test-path "$TargetFolder" -pathType container)) {
|
||||||
throw "Target folder at 📂$Directory doesn't exist"
|
throw "Target folder at 📂$TargetFolder doesn't exist"
|
||||||
}
|
}
|
||||||
$Time = (Get-Date)
|
$Time = (Get-Date)
|
||||||
$Filename = "$($Time.Year)-$($Time.Month)-$($Time.Day)T$($Time.Hour)-$($Time.Minute)-$($Time.Second).png"
|
$Filename = "$($Time.Year)-$($Time.Month)-$($Time.Day)T$($Time.Hour)-$($Time.Minute)-$($Time.Second).png"
|
||||||
$FilePath = (Join-Path $Directory $Filename)
|
$FilePath = (Join-Path $TargetFolder $Filename)
|
||||||
TakeScreenshot $FilePath
|
TakeScreenshot $FilePath
|
||||||
|
|
||||||
"✔️ screenshot saved to $FilePath"
|
"✔️ screenshot saved to $FilePath"
|
||||||
|
Loading…
Reference in New Issue
Block a user