Score:0

PowerShell: Why am I getting this error?

cn flag

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

Score:2
us flag

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.

Tony Chong avatar
cn flag
Not it says access is denied.
Mike Shepard avatar
us flag
Then your current creds probably don't have access.
Tony Chong avatar
cn flag
I am logged in as an administrator. Is there anything else I can do?
Mike Shepard avatar
us flag
You can try passing the credentials explicitly with -Credential
Mike Shepard avatar
us flag
Here's a link to a page on PowerShell remoting security. There are lots of things that can be going on now...https://docs.microsoft.com/en-us/powershell/scripting/learn/remoting/winrmsecurity?view=powershell-5.1
ua flag
"*I am logged in as an administrator. Is there anything else I can do?*" - did you also right-click "Run as administrator" on PowerShell, so it says "Administrator: Windows PowerShell" in the title, @TonyChong
Score:0
cn flag

Ok, so the answer to my question was that I had to pass the credentials explicitly by using the Credential parameter AND create a new PSSession with the same command. This is because PowerShell has too much attitude.

Invoke-Command -Session (NewPSSession WIN-9F8JQL85GIA -Credential AD\Administrator) -ScriptBlock {Get-EventLog -LogName Security -Newest 100}

That is the correct answer.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.