Powershellでselemiumを用いてフルスクリーンショットを取得するコード

# Seleniumをインポート
#Add-Type -Path "C:\path\to\Selenium.WebDriver.dll"
#Add-Type -Path "C:\path\to\Selenium.WebDriver.ChromeDriver.dll"
try {
    Import-Module -Name Selenium -ErrorAction Stop
}
catch {
    Write-Host 'Importing the Selenium module failed. Please install it using the following command: Install-Module Selenium'
    break
}
# ヘッドレスモードを有効にする
$chromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions;
$chromeOptions.AddArgument("--headless");
#Chromeブラウザを起動
#コマンドレット(ヘッドレスモードなし)
#Driver = Start-SeChrome
$Driver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($chromeOptions)
if (!$Driver) {
    Write-Host "The selenium driver was not running." -ForegroundColor Yellow
    Return
}


Enter-SeUrl ’URL’ -Driver $Driver

#通常スクリーンショット
#$Screenshot = New-SeScreenshot -Target $Driver
#$Screenshot = Invoke-SeScreenshot -Target $Driver
#$Screenshot = $Driver.GetScreenshot() #.SaveAsFile("C:\screenshot.png", [System.Drawing.Imaging.ImageFormat]::Png)
#Save-SeScreenshot -Screenshot $Screenshot -Path ./1.png

#フルスクリーンショット準備
$map = New-Object 'System.Collections.Generic.Dictionary[System.String,System.Object]';
$map['captureBeyondViewport'] = $true;
$Screenshot = $Driver.ExecuteChromeCommandWithResult("Page.captureScreenshot", $map)
Save-SeScreenshot -Screenshot $Screenshot['data'] -Path ./1.png

# ブラウザを閉じる
# コマンドレットで閉じる。
#Stop-SeDriver -Driver $Driver
$Driver.Quit()