beginner question

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 3 years, 6 months ago.

  • Author
    Posts
  • #12027
    Profile photo of Frank VansEvers
    Frank VansEvers
    Participant

    I am trying to type the following:
    $a = get content myfile.txt
    $a | foreach (get-hotfix -computername $_ | sort installedon)[-1]
    what am I doing wrong?
    if I type:
    (get-hotfix -computername thename | sort installedon)[-1]
    works great
    sorry if dump question, just begining.
    /s/ Frank in Florida

  • #12030
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    ForEach-Object takes (at least) one ScriptBlock parameter, and ScriptBlocks have curly braces around them (which are missing in your code). You also appear to be missing a hyphen in the Get-Content cmdlet. For example:

    Get-Content -Path MyFile.txt |
    ForEach-Object {
        Get-Hotfix -ComputerName $_ |
        Sort-Object InstalledOn
    }
    

You must be logged in to reply to this topic.