Why?
There is little reason to try and script this.
MS Edge on Windows 10 and higher already has a screen capture feature. You just need to enable it. It's called 'Web Capture '.
https://techcommunity.microsoft.com/t5/articles/introducing-web-capture-for-microsoft-edge/m-p/1721318
Note, if you are just trying to capture stuff on-screen real-time for documentation, then look at the built-in Windows OS Problem Step Recorder(PSR) tool.
https://learn.microsoft.com/en-us/office/troubleshoot/settings/how-to-use-problem-steps-recorder
It's been in Windows for decades.
Lastly, there are already modules in the mspowershellgallery.com that can also provide screen capture.
Find-Module -Name '*screenshot*'
Version Name Repository Description
------- ---- ---------- -----------
1.0 PSScreenshot PSGallery Save a screenshot from PowerShell.
6.0.0 Invoke-ExportServerScreenShotREDFISH PSGallery iDRAC cmdlet using Redfish API with ...
If you absolutely want to script this manually, you can do something like this. Though this is not MSEdge specific, this can be used for whatever, as it's for the whole primary screen.
Add-Type -AssemblyName System.Windows.Forms,
System.Drawing
Start-Process -FilePath 'msedge' -ArgumentList '-inprivate', 'https://www.google.com' -Wait
$screens = [Windows.Forms.Screen]::PrimaryScreen
$top = ($screens.Bounds.Top |
Measure-Object -Minimum).Minimum
$left = ($screens.Bounds.Left |
Measure-Object -Minimum).Minimum
$width = ($screens.Bounds.Right |
Measure-Object -Maximum).Maximum
$height = ($screens.Bounds.Bottom |
Measure-Object -Maximum).Maximum
$bounds = [Drawing.Rectangle]::FromLTRB($left, $top, $width, $height)
$bmp = New-Object System.Drawing.Bitmap ([int]$bounds.width), ([int]$bounds.height)
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save("$env:USERPROFILE\Desktop\test.jpg")
$graphics.Dispose()
$bmp.Dispose()
Update
To minimize questions. As per my comment, you'd end up doing a command like this as the last line. You are going to have to play around to find one that will consistently work for your use case(s).
[System.Windows.Forms.SendKeys]::SendWait('% n {ENTER}')
Note:
This is not unique, there are tons of others like this all over the web, right here on SO, and shown in Youtube videos.