Using hotfix in for each loop

Welcome Forums General PowerShell Q&A Using hotfix in for each loop

Viewing 1 reply thread
  • Author
    Posts
    • #187018
      Participant
      Topics: 20
      Replies: 53
      Points: 139
      Rank: Participant

      Good morning experts!
      Looking for some help to use hotfix to grab servername, kb number and date into one file so I can compare them. Here is what we have so far

      $admin=Get-Credential
      $Servers=Get-Content C:\WVUS\SQL_Servers.txt
      $date=[datetime]::Today.ToString('MM-dd-yyyy')
      
       
      
      
      ForeEach ($Server in $Servers) {
      Invoke-Command -ComputerName $Server -ScriptBlock { "$(Get-HotFix)" } -Credential $admin | Out-File -filepath c:\Temp\SQL_SERVERS_KB_$date.txt -Append
      }
      

      Thanks in advance for your input

      Norm

    • #187021
      Senior Moderator
      Topics: 8
      Replies: 1123
      Points: 3,831
      Helping Hand
      Rank: Community Hero

      a generic advice,

      Just write code to get hotfix from the localmachine in the desired output format. Once ready, then us Invoke-Command to target multiple computers.

      PS: Get-Hotfix do have a -ComputerName parameter, using that'll will be better here.

      Get-HotFix -ComputerName (Get-Content -Path ) | Export-CSV  -NoTypeInformation
      
Viewing 1 reply thread
  • You must be logged in to reply to this topic.