How to pass the AWS SSM output with powershell script

455 Views Asked by At

I was trying create a report for windows update as when the server get patched last also i am trying to combine the aws ssm out with the script

i.e i fetch the instance details with aws ssm describe command and stored in a variable then i pass it in a for loop and try to fetch the server last patch date, but it return empty values, pls help me to achieve this

The output is

pscomutername HotFixID InstalledBy InstalledOn

My code is

 $list= (aws ssm describe-instance-patch-states-for-patch-group --patch-group "DEV" --query "Reservations[*].Instances[*].Tags[?Key=='Name'].Value" --profile "xxxxxx" --region "us-west-2" --output text)
    foreach ($server in $list)
    { 
    {Get-CimInstance -Class win32_quickfixengineering  |  
    Where-Object InstalledOn -gt (Get-Date).AddDays(-30)} |  
    Select-Object PSComputerName,HotFixID,InstalledBy,InstalledOn | Sort-Object PSComputerName
    }
1

There are 1 best solutions below

0
On

You need to pass your $server variable to the -ComputerName argument of Get-CimInstance to make it operate on a remote server. And those brackets are causing problems because they crate CodeBlocks which needs to be manually invoked, so Get-CimInstance is never actually invoked. I suspect what you actually want is something like this:

$list= (aws ssm describe-instance-patch-states-for-patch-group --patch-group "DEV" --query "Reservations[*].Instances[*].Tags[?Key=='Name'].Value" --profile "xxxxxx" --region "us-west-2" --output text)
foreach ($server in $list)
{ 
  Get-CimInstance -Class win32_quickfixengineering -ComputerName $server |  
    Where-Object InstalledOn -gt (Get-Date).AddDays(-30) |
    Select-Object PSComputerName,HotFixID,InstalledBy,InstalledOn | Sort-Object PSComputerName
}