beginner question

Welcome Forums General PowerShell Q&A beginner question

This topic contains 1 reply, has 2 voices, and was last updated by

 
Member
4 years, 12 months ago.

  • Author
    Posts
  • #12027

    Participant
    Points: 0
    Rank: Member

    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

    Member
    Points: 0
    Rank: Member

    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
    }
    

The topic ‘beginner question’ is closed to new replies.