beginner question

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

  • Author
  • #12027

    Frank VansEvers

    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

    Dave Wyatt

    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.