I'm trying to supply command line arguments to the "net accounts" command. This works when writing out the command without variables, but doesn't when passing the command line arguments with a variable.
Here's a demo script:
Write-Host "--- As variable"
$Sw = "/lockoutduration:15 /lockoutwindow:15"
Write-Host $Sw
&net.exe accounts $Sw
Write-Host "--- Without variable"
&net.exe accounts /lockoutduration:15 /lockoutwindow:15
Output:
> .\Test.ps1
--- As variable
/lockoutduration:15 /lockoutwindow:15
You entered an invalid value for the /LOCKOUTDURATION option.
More help is available by typing NET HELPMSG 3952.
--- Without variable
The command completed successfully.
What's the way to supply a set of command line arguments?
OS: Windows 10 Pro 20H2, Powershell version: 5.1