I'm new to Powershell. When I run the following command from within a ps1 file:
add-computer -DomainName "example.com" -NewName "adfsserver" -restart
...I get this error:
A positional parameter cannot be found that accepts argument 'example.com'
+ add-computer ?DomainName "example.com" -NewName "adfsserver" -restart
Interestingly, if I simply open a PowerShell window and paste this command in, it works fine (though it prompts me for credentials).
For me, a positional parameter is a parameter whose value is determined by its relative position in a parameter list. I don't see that I'm using any positional parameters, I'm using named parameters (or named keys, whatever Powershell calls it). According to the examples here I'm using -DomainName correctly. I can't tell it it is objecting to "-DomainName" or "example.com".
And for the life of me I don't understand why the command works perfectly fine when I type it in manually - does Windows have different PowerShell parsers that work differently in different places?