Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

Powershell Multiple URL Screenshot

$
0
0

I need a powershell script that opens multiple URLs in Firefox, takes a screenshot of each page and places it on a specific path. I've already built it for 1 Url and an multiple interval Screenshot. I dont know how to change it for more URLs: 

[system.Diagnostics.Process]::Start("firefox","https://developers.google.com/speed/pagespeed/insights/?hl=de&url=https%3A%2F%2Fwww.jaz-hotel.com%2Fhotels%2Fjaz-in-the-city-amsterdam")#region Function definitions
Function Get-ScreenShot

    [CmdletBinding(DefaultParameterSetName='Directory', PositionalBinding=$false)]
    Param(
        [Parameter(ParameterSetName='File')]
        [Parameter(Mandatory=$false, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$False)]
        [ValidateScript({$_  -match "\.(bmp|gif|jpg|png|wmf)$"})]
        [string]$FullName,

        [Parameter(ParameterSetName='Directory')]
        [Parameter(Mandatory=$false, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$False)]
        [string]$Directory,

        [Parameter(ParameterSetName='Directory')]
        [parameter(Mandatory=$false)]
        [ValidateSet('bmp','gif','jpg','png','wmf')]
        [String]$Format='png',

        [Parameter(ParameterSetName='Directory')]
        [parameter(Mandatory=$false)]
        [ValidateScript({$_ -ge 0})]
        [int]$DurationInSeconds=0,

        [Parameter(ParameterSetName='Directory')]
        [parameter(Mandatory=$false)]
        [ValidateScript({$_ -ge 0})]
        [int]$IntervalInSeconds=0,

        [parameter(Mandatory=$false)]
        [ValidateSet('VirtualScreen','WorkingArea')]
        [String]$Area='WorkingArea',

        [parameter(Mandatory=$false)]
        [Switch]$Beep
    )

    
    Add-Type -AssemblyName System.Windows.Forms
    Add-type -AssemblyName System.Drawing
    # Gather Screen resolution information
    #$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
    #$Screen = [System.Windows.Forms.SystemInformation]::WorkingArea
    $Screen = [System.Windows.Forms.SystemInformation]::$Area
    $Width = $Screen.Width
    $Height = $Screen.Height
    $Left = $Screen.Left
    $Top = $Screen.Top
    $TimeElapsed = 0
    $IsTimeStampedFileName = $false
    if ($FullName)
    {
        $Directory = Split-Path -Path $FullName -Parent
        $HasExtension = $FullName -match "\.(?<Extension>\w+)$"
        if ($HasExtension)
        {
            $Format = $Matches['Extension']
        }
        New-Item -Path $Directory -ItemType Directory -Force | Out-Null
    }
    elseif ($Directory)
    {
        New-Item -Path $Directory -ItemType Directory -Force | Out-Null
        $FullName = Join-Path -Path $Directory -ChildPath $((get-date -f yyyyMMddTHHmmss)+".$Format")
        $IsTimeStampedFileName = $true
    }
    else
    {
        $Directory = [Environment]::GetFolderPath('MyPictures')
        Write-Verbose "Target directory not specified we use [$Directory]"
        $FullName = Join-Path -Path $Directory -ChildPath $((get-date -f yyyyMMddTHHmmss)+".$Format")
        $IsTimeStampedFileName = $true
    }

    switch ($Format)
    {
        'bmp' { $Imageformat= [System.Drawing.Imaging.ImageFormat]::Bmp; }
        'gif' { $Imageformat= [System.Drawing.Imaging.ImageFormat]::Gif; }
        'jpg' { $Imageformat= [System.Drawing.Imaging.ImageFormat]::Jpeg; }
        'png' { $Imageformat= [System.Drawing.Imaging.ImageFormat]::Png; }
        'wmf' { $Imageformat= [System.Drawing.Imaging.ImageFormat]::Wmf; }
    }

    do
    {
        # Create bitmap using the top-left and bottom-right bounds
        $Bitmap = New-Object -TypeName System.Drawing.Bitmap -ArgumentList $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($FullName, $Imageformat)
        Write-Verbose -Message "[$(get-date -Format T)] Screenshot saved to $FullName"
        if ($Beep)
        {
            [console]::beep()
        }
        
        if (($DurationInSeconds -gt 0) -and ($IntervalInSeconds -gt 0))
        {
            Write-Verbose "[$(get-date -Format T)] Sleeping $IntervalInSeconds seconds ..."
            Start-Sleep -Seconds $IntervalInSeconds
            $TimeElapsed += $IntervalInSeconds
        }
        if ($IsTimeStampedFileName)
        {
            $FullName = Join-Path -Path $Directory -ChildPath $((get-date -f yyyyMMddTHHmmss)+".$Format")
        }
    } While ($TimeElapsed -lt $DurationInSeconds)
}    
#endregion

Clear-Host
New-Alias -Name New-ScreenShoot -Value Get-ScreenShot -ErrorAction SilentlyContinue
#Get-ScreenShot -Verbose
Get-ScreenShot -Directory 'C:\Users\gianluca.hoffmann' -Format jpg -DurationInSeconds 500 -IntervalInSeconds 50 -Area WorkingArea -Beep -Verbose
#Get-ScreenShot -FullName 'C:\Users\gianluca.hoffmann\screenshot.wmf' -Verbose


Viewing all articles
Browse latest Browse all 2314


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>