Tom McMeekin
Tom McMeekin

Reputation: 11

Missing argument in parameter list

NooB qustion...I'm attempting to run the following command from a cmd shell and receiving a missing argument error. Interestingly if I parse PowerShell command directly into a PS command prompt I don't get any errors.

Hopefully, a simple typo that someone can help check the syntax for.

CMD.exe Command:

powershell.exe -Command Add-Computer -DomainName mydomain -Credential (New-Object System.Management.Automation.PSCredential("mydomain\admin", (ConvertTo-SecureString "W/GdGax+1CebYQ74" -AsPlainText -Force)))

ERROR:

At line:1 char:115
+ ... ect System.Management.Automation.PSCredential(mydomain\admin, (Conver ...
+                                                                 ~
Missing argument in parameter list.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingArgument*

Upvotes: 1

Views: 33932

Answers (4)

Kiran Bakale
Kiran Bakale

Reputation: 1

Please make sure your source filename doesn't include any commas (,), hyphens (-), or any special symbols, like my filename did:

screenshot

Once you remove them it works. The error may differ in its description but the reason is same.

Upvotes: 0

Jörg
Jörg

Reputation: 2494

Just add outer quotes to delimit the line sent as one command

and escape all the quotes inside the command, like so:

powershell.exe -Command "Add-Computer -DomainName mydomain -Credential (New-Object System.Management.Automation.PSCredential(\"mydomain\admin\", (ConvertTo-SecureString \"W/GdGax+1CebYQ74\" -AsPlainText -Force)))"

Upvotes: 0

SantiCarta
SantiCarta

Reputation: 106

If you try to run this as a .ps1 script does the same thing?

powershell.exe -file yourScript.ps1

Upvotes: 0

I was able to reproduce your problem. For instantiating Credential I tried to pass TypeName and ArgumentList separately as below and this works. Can you please give this a try:

powershell.exe -Command "Add-Computer" -DomainName "mydomain" -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "mydomain\admin", (ConvertTo-SecureString "W/GdGax+1CebYQ74" -AsPlainText - Force))

Upvotes: 2

Related Questions