i am not a programmer but i am trying to run this powershell script to get multiple website screenshots with internet exporer ( not my script )
can anyone help to find out what is wrong with it because i am stack and i dont know what to do.
thnx in advance
# Author: Shawn Keene
# Date: 09/12/2019
# Powershell script to automate Internet Explorer and grab screenshots
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
cd $ScriptPath
[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()
}
$bounds = [Drawing.Rectangle]::FromLTRB(4, 110, 1580, 1584) #area for screenshot
cls
Write-Host -ForegroundColor Yellow "Starting... Move or minimize this window."
sleep 3 #give the user 3 seconds to minimize
or move the powershell window out of the way
$iterator = 1;
$OutputFile = "screenshot-log.log" #just in case we need to debug
something later
$products = import-csv "urls.csv" | foreach { #load a 2-column CSV with headers of
"filename" (for picture file) and "url" to visit
$ie = New-Object -com internetexplorer.application; #initialize a fresh browser window for
each row of the CSV
$ie.top = 0;
$ie.left = -8; #because windows 10 has an invisible
grab borders unless you use AeroLite theme
$ie.height = 1600;
$ie.width = 1600;
$ie.visible = $true;
$ie.navigate("about:blank");
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1};
$startTime = Get-Date #start the stopwatch and log it
write-host $iterator.ToString() `t $_.url
$ie.navigate($_.url); #go to the website and wait for browser
to become idle
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1};
sleep 3 #wait at least 3 seconds and then check
for idle one more time to be sure
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1};
$endTime = get-date #end timer
$filepath = "Results\" + $_.filename + ".png" #place screenshots into the Results
subfolder of the current working directory
screenshot $bounds $scriptpath\$filepath #say cheese
#log the result to the log file
$iterator.ToString() + "`t" + $_.filename + "`t" + $_.url + "`t" + $startTime.DateTime + "`t" +
($endTime - $startTime).TotalSeconds + " seconds" >> $outputFile
$ie.quit(); #close the browser process
$iterator = $iterator+1;
}
Write-Host -ForegroundColor Green "All Done!";
and i am get this error
Exception calling "Save" with "1" argument(s): "The given path's format is not supported."
At line:7 char:4
+ $bmp.Save($path)
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NotSupportedException
can anyone help to find out what is wrong with it because i am stack and i dont know what to do.
thnx in advance