Skip to content

Instantly share code, notes, and snippets.

@adumont
Created January 3, 2017 17:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save adumont/bbdfbd0f63be8719b1af87d862a45c56 to your computer and use it in GitHub Desktop.
Save adumont/bbdfbd0f63be8719b1af87d862a45c56 to your computer and use it in GitHub Desktop.
Takes screenshot of multiple websites by URL
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function Screenshot([Drawing.Rectangle]$bounds, $path) {
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save($path)
$graphics.Dispose()
$bmp.Dispose()
}
$data = Import-Excel 'D:\temp\Azure.xlsx' -Sheet websites
$data | ForEach-Object {
$website = $_
$url=$website.Hostnames.Split(',')[0]
Write-Host $website.Name $url
$IE=new-object -com internetexplorer.application
$IE.visible=$true
$IE.FullScreen=$false
$IE.ToolBar = $false
$IE.StatusBar = $false
$IE.MenuBar = $false
$IE.AddressBar = $true
$IE.Resizable = $true
$IE.Top = 0
$IE.Left = 577
$IE.Width = 1024
$IE.Height = 747
$IE.navigate2( $url )
$i=0
While ( $IE.busy -eq $true ) {
Start-Sleep -s 1
$i = $i + 1
if ( $i -ge 20 ) { break }
}
$bounds = [Drawing.Rectangle]::FromLTRB($IE.Left, $IE.Top, $IE.Left + $IE.Width, $IE.Top + $IE.Height)
$filename = "D:\temp\urlshots\"+ ($website.Name) +".png"
Screenshot $bounds $filename
$IE.Quit()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment