Public/Start-Capture.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
<#
.SYNOPSIS Start creating your gif .DESCRIPTION Start capturing screenshots of either the active window or your full screen and generate a gif .PARAMETER Screen Screenshot of the entire screen .PARAMTER ActiveWindow Screenshot of the active window .PARAMETER Milliseconds Milliseconds between screenshot .PARAMTER FilePath Name and location to save the generated gif .EXAMPLE 1 Start-Capture -Screen -FilePath "c:\users\msadministrator\Desktop\mynewgif.gif" .NOTES Name: Start-Capture Author: Josh Rickard (MSAdministrator) DateCreated: 07/07/2018 #> function Start-Capture { [CmdletBinding(DefaultParameterSetName = 'screen', SupportsShouldProcess = $true, PositionalBinding = $false, HelpUri = '', ConfirmImpact = 'Medium')] Param ( # Screenshot of the entire screen [Parameter( Mandatory = $false, ParameterSetName = "screen", ValueFromPipelineByPropertyName = $true)] [switch]$Screen, # Screenshot of the active window [Parameter( Mandatory = $false, ParameterSetName = "window", ValueFromPipelineByPropertyName = $true)] [switch]$ActiveWindow, # Milliseconds between screenshot [Parameter( Mandatory = $false, ValueFromPipelineByPropertyName = $true)] [int]$Milliseconds = '1000', # Name and location to save the generated gif [Parameter( Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [ValidateScript( { if ($_ -notmatch "(\.gif)") { throw "The file specified in the path argument must be type of gif" } return $True } ) ] [string]$FilePath ) $script:GifFilePath = $FilePath try { if (Get-ChildItem -Path "$env:TEMP\CaptureIT\" -ErrorAction SilentlyContinue) { try { [IO.File]::OpenWrite($file).close(); } catch {} Remove-Item -Path "$env:TEMP\CaptureIT\" -Recurse -Force } } catch { Write-Error -ErrorRecord $Error[0] -RecommendedAction "Please remove stale screenshots from $env:TEMP\CaptureIT\" } if ($Screen) { if ($pscmdlet.ShouldProcess("Entire Screen", "Begin Capturing")) { try { Write-Verbose -Message 'Calling Start-FullScreenCapture' Start-FullScreenCapture -Milliseconds $Milliseconds } catch { Write-Error -ErrorRecord $Error[0] exit -1 } try { Write-Verbose -Message 'Attempting to generate gif' ConvertTo-Gif -FilePath $script:GifFilePath } catch { Write-Error -ErrorRecord $Error[0] } } } elseif ($ActiveWindow) { if ($pscmdlet.ShouldProcess("Active Window", "Begin Capturing")) { try { Write-Verbose -Message 'Calling Start-ActiveWindowCapture' Start-ActiveWindowCapture -Milliseconds $Milliseconds } catch { Write-Error -ErrorRecord $Error[0] exit -1 } try { Write-Verbose -Message 'Attempting to generate gif' ConvertTo-Gif -FilePath $script:GifFilePath } catch { Write-Error -ErrorRecord $Error[0] } } } else { Write-Warning -Message 'Please add a switch to indicate if you want to capture the Full Screen or Active Window' } } |