Pulling my hair out

Welcome Forums General PowerShell Q&A Pulling my hair out

Viewing 2 reply threads
  • Author
    Posts
    • #211245
      Participant
      Topics: 12
      Replies: 11
      Points: 156
      Rank: Participant

      Hello All,

      I have been writing snippets of code and testing them before i build a larger script.

      Goal is to get a list of servers from my environment put it into a variable then use get-hotfix to read each of the server names in the variable and output a list of hotfixes on screen..

      $Computers = Get-ADComputer  -identity *

      First step put all server names in $computer variable

      Now run through loop

      Foreach ($computer in $computers)

      now open action block

      {get-hotfix | select hotfixID, Description}

       

      The challenge I am facing is nothing is output to screen. Spending hours trying to get this to work but I am hitting a dead wall.

       

      Can someone please suggest ideas/thoughts ? perhaps I am going down the wrong path.

       

      Best wishes

       

       

       

       

    • #211257
      Participant
      Topics: 4
      Replies: 2247
      Points: 5,484
      Helping Hand
      Rank: Community MVP

      Please, when you post code format it as code using the code tags “PRE“. Thanks

      When you use Get-ADComputer with the parameter -Identity you have to provide an existing unique identifier of a computer object in your AD. It can be a A distinguished name, a GUID (objectGUID), a security identifier (objectSid) or a Security Accounts Manager account name (sAMAccountName). If you want to collect a bunch of computers from your AD you will have to use the -Filter parameter with the asterisk “*”. But you should limit the search with the parameter -SearchBase to lower the stress you put on your AD to get this list.

      Assuming not all of the computers in your network are reachable all the time you should check the connectivity before you try to query their hotfix status. Something like this could be a starting point:

      $SearchBase = 'OU=Computers,OU=SampleDepartement,OU=SampleSite,OU=SampleRegion,DC=SampleCompany,DC=com'
      $ComputerList = Get-ADComputer -SearchBase $SearchBase -Filter * 
      
      foreach($ComputerName in $ComputerList.Name){
          if(Test-Connection -ComputerName $ComputerName -Count 1 -Quiet){
              Get-HotFix -ComputerName $ComputerName
          }
      }

      You should always read the complete help including the examples for the cmdlets you’re about to use to learn how to use them and to learn what they are capable of.

    • #211461
      Participant
      Topics: 12
      Replies: 11
      Points: 156
      Rank: Participant

      Olaf your assistance again is once more appreciated. You are really helping to fill gaps in my knowledge when it comes to Powershell.

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