PowerShell: Why am I getting this error?

I am trying to use the PowerShell Invoke command. I am using it correct but I don't know why I am getting an error.

Invoke-Command Get-EventLog –LogName Security –Newest 100 -ComputerName WIN-9F8JQL0989

The error message:

Error message


Solution 1:

I'm guessing you want to get the newest 100 security event logs from the named computer.

To do that, you just missed some braces:

Invoke-Command { Get-EventLog –LogName Security –Newest 100} -ComputerName WIN-9F8JQL0989

The braces denote the scriptblock/payload that you want to execute (the command).

The error you were getting was because you had mixed the command-lines for invoke-command and get-eventlog, so the parser couldn't figure out which parameters belonged where. It thought the -LogName (and -Newest for that matter) was being used with invoke-command, and it doesn't have that parameter.