none
Getting cmdlet ForEach-Object at command pipeline position 1

    Question

  • 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" }

    Friday, February 01, 2013 2:42 PM

Answers

  • Hi,

    I recommend starting with the Learn link at the top of this forum.

    Bill

    Friday, February 01, 2013 3:22 PM
    Moderator
  • 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)


    ¯\_(ツ)_/¯

    Friday, February 01, 2013 5:43 PM

All replies

  • Hi,

    I recommend starting with the Learn link at the top of this forum.

    Bill

    Friday, February 01, 2013 3:22 PM
    Moderator
  • 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)


    ¯\_(ツ)_/¯

    Friday, February 01, 2013 5:43 PM