Last active
April 5, 2019 22:31
-
-
Save austoonz/7f8434f840480c2d55558bef23ea685e to your computer and use it in GitHub Desktop.
Sample code for writing an AWS Systems Manager Compliance Item.
This file contains 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 |
Write-SSMCompliance posts compliance items to Systems Manager Compliance, and IIRC overwrites based on the ComplianceType field.
This gist demonstrates how to post your own Inventory data.
https://gist.github.com/austoonz/0e8a4ff8c9b26c81d6a2b4ddc9b5f63f
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this! This is a great help to get started. From my slack message...