-
-
Save sheldonhull/f42eeca4f4489fc00d810ca9ec4ff79e to your computer and use it in GitHub Desktop.
Sample code for writing an AWS Systems Manager Compliance Item.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$managedInstanceId = (Get-Content -Path 'C:\ProgramData\Amazon\SSM\InstanceData\Vault\Store\RegistrationKey' -Raw | ConvertFrom-Json).instanceID | |
$moduleNames = @( | |
'AWSPowerShell', | |
'ClipboardText', | |
'Convert', | |
'PSWindowsUpdate' | |
) | |
$complianceItems = [System.Collections.Generic.List[Amazon.SimpleSystemsManagement.Model.ComplianceItemEntry]]::new() | |
foreach ($moduleName in $moduleNames) | |
{ | |
$module = Get-Module -Name $moduleName -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1 | |
$item = [Amazon.SimpleSystemsManagement.Model.ComplianceItemEntry]::new() | |
$item.Id = $module.Version.ToString() | |
$item.Severity = [Amazon.SimpleSystemsManagement.ComplianceSeverity]::INFORMATIONAL | |
$item.Status = [Amazon.SimpleSystemsManagement.ComplianceStatus]::COMPLIANT | |
$item.Title = $moduleName | |
$null = $complianceItems.Add($item) | |
} | |
$writeSSMComplianceItem = @{ | |
ComplianceType = 'Custom:PowerShellModule' | |
ResourceId = $managedInstanceId | |
ResourceType = 'ManagedInstance' | |
Item = $complianceItems | |
ExecutionSummary_ExecutionTime = Get-Date | |
ExecutionSummary_ExecutionType = 'Command' | |
} | |
Write-SSMComplianceItem @writeSSMComplianceItem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment