Filter by computer name then find last Windows client update

Welcome Forums General PowerShell Q&A Filter by computer name then find last Windows client update

Viewing 4 reply threads
  • Author
    Posts
    • #239837
      Participant
      Topics: 1
      Replies: 2
      Points: 19
      Rank: Member

      Hi!

      I am very new to powershell so apologies if this question is noobish.

      In a domain I am attempting to filter by computer name then show for each the last update for each filtered Windows 10 client.

      The filtering part seems to function, but interogating each to get the last update is wrong.

      Get-ADComputer -filter * | Where-Object {$_.Name -like "abcad*"} | select -ExpandProperty Name
      foreach{Get-HotFix -ComputerName $_ | Sort-object InstalledOn -Descending | Select-object -first 1
      }

      Any assistance would be appreciated!

      Thanks

      John

      • This topic was modified 1 month, 1 week ago by James Petty.
    • #239843
      Participant
      Topics: 5
      Replies: 2422
      Points: 6,253
      Helping Hand
      Rank: Community MVP

      John, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

      When you post code, error messages, sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

      To reduce the stress you put on your DC with a query like this I urgently recommend using the -SearchBase parameter for Get-ADUser. It would also be faster when you use the -Filter parameter of Get-ADUser instead of filtering the results provided by it later with a Where-Object.

      The actual mistake you did – you forgot to pipe the output of “select -ExpandProperty Name” to Foreach-Object. 😉

      Something like this should run actually

      $SearchBase = 'OU=Computers,OU=Departement,DC=contoso,DC=com'
      
      Get-ADComputer -Filter "Name -like 'abcad*'" -SearchBase $SearchBase |
      ForEach-Object {
          Get-HotFix -ComputerName $_.Name |
          Sort-Object -Property InstalledOn |
          Select-Object -Last 1
      }

      … untested. I don’t have an environment to test at the moment.

      And just for the sake of completeness – all computers you want to query that way have to be switched on and reachable on the network.

    • #240449
      Participant
      Topics: 1
      Replies: 2
      Points: 19
      Rank: Member

      Many Thanks Olaf!

      I will follow your advice and aim to get it working in the coming week.  I will report back what happens.

       

      Thanks again for your time!

    • #241529
      Participant
      Topics: 1
      Replies: 2
      Points: 19
      Rank: Member

      Hi

      Further to the earlier post, I’ve been attempting to filter by computer name then show for each the last update for each filtered Windows 10 client using this script:

      $SearchBase = “OU=PHS,OU=RSS,OU=Computers,DC=org,DC=uk”
      Get-ADComputer -Filter “Name -like ‘abcad*'” | -SearchBase $SearchBase |
      ForEach-Object {
      Get-HotFix -ComputerName $_.Name |
      Sort-Object -Property InstalledOn -Descending |
      Select-Object -first 1
      }
      

       

      In response I am getting the following error message:

      -SearchBase : The term ‘-SearchBase’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
      try again.
      At line:1 char:47
      + Get-ADComputer -Filter “Name -like ‘abcad*'” | -SearchBase $SearchBase |
      + ~~~~~~~~~~~
      + CategoryInfo : ObjectNotFound: (-SearchBase:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException

      I would be grateful for any assistance.

      Many thanks!

      JF

    • #241538
      Participant
      Topics: 5
      Replies: 2422
      Points: 6,253
      Helping Hand
      Rank: Community MVP

      -SearchBase is parameter for the cmdlet Get-ADUser. Please always read the complete help including the examples for the cmdlets you’re about to use to learn how to use them.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.