MrJoeyJoeJoey
MrJoeyJoeJoey

Reputation: 61

How to add arguments to Diagnostic Start with PowerShell

I am limited to only using native windows tools, and I need to automate opening a browser, going to a website, and then closing the browser. I'm going to use task scheduler to run the script.

I created this PowerShell script which successfully opens a browser, and closes it. How would I go about having this open a specific webpage? Start Arguments or something else?

$browser = [Diagnostics.Process]::Start("chrome.exe")
$id = $browser.Id
Start-Sleep -Seconds 5
try {
    Stop-Process -Id $id -ErrorAction stop
} catch {
    Write-Host "Failed to kill"
}    

Upvotes: 0

Views: 139

Answers (1)

D-squared
D-squared

Reputation: 331

You can start the process with the appropriate Chromium command line argument(s):

$browser = [Diagnostics.Process]::Start("chrome.exe", "https://stackoverflow.com/ --new-window")
$id = $browser.Id
Start-Sleep -Seconds 5
try {
    Stop-Process -Id $id -ErrorAction stop
}
catch {
    Write-Host "Failed to kill"
} 

Process.Start Method
Run Chromium with flags
List of Chromium Command Line Switches

Upvotes: 2

Related Questions