0

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

1 Answer 1

3

When sending multiple arguments to a program you need to pass them as an array. Try:

Write-Host "--- As variable"
$Sw = @("/lockoutduration:15","/lockoutwindow:15")
$Sw
&net.exe accounts $Sw
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.