Getting cmdlet ForEach-Object at command pipeline position 1
-
Friday, February 01, 2013 2:42 PM
Hi there,
I'm trying to run the provided script posted online and I getting the following when I type it in.> ./Get-EventsByWmi.ps1 -computer c:\fso\myservers.txt -log system -eventid 21
cmdlet ForEach-Object at command pipeline position 1
Supply values for the following parameters:
Process[0]:Here is the script.......
Param(
[string[]]$computer = (Get-Content -path c:\fso\servers.txt),
[string]$log = "system",
[string]$eventID = 21
) #end param
Function Get-EventsByWmi($computerName,$log,$eventID)
{
Get-WmiObject -Class win32_NTLogEvent -filter "logfile = '$log' and EventCode = '$eventID'" -computerName $computerName
} #end Get-EventsByWmi
# *** Entry Point to Script ***
if(-not($computer)) {"you must supply name for computer"; exit}
$computer |
Foreach -begin { "Querying $log Log for EventID: $eventID" } `
-process { Get-EventsByWmi -ComputerName $_ -log $log -eventID $eventID } `
-end { "Completed querying $computer.length computers" }
All Replies
-
Friday, February 01, 2013 3:22 PMModerator
- Proposed As Answer by Bill_StewartMicrosoft Community Contributor, Moderator Wednesday, February 06, 2013 6:32 PM
- Marked As Answer by IamMredMicrosoft Employee, Owner Tuesday, March 05, 2013 3:41 AM
-
Friday, February 01, 2013 5:43 PM
That script is one that would never work because there are some very specific errors. Much of the syntax is wrong. You would be better off writing your own script from scratch. Start with Bill's suggestion.
(I see three serious mistakes in what you posted. - The writer of the script did not know PowerShell)
¯\_(ツ)_/¯
- Marked As Answer by IamMredMicrosoft Employee, Owner Tuesday, March 05, 2013 3:41 AM

