Created
January 25, 2019 06:09
-
-
Save austoonz/0e8a4ff8c9b26c81d6a2b4ddc9b5f63f to your computer and use it in GitHub Desktop.
Sample code for writing an AWS Systems Manager Inventory record.
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
$powerShellModules = Get-Module -ListAvailable | |
$date = Get-Date -UFormat '+%Y-%m-%dT%H:%M:%SZ' | |
$inventoryItems = [System.Collections.Generic.List[Amazon.SimpleSystemsManagement.Model.InventoryItem]]::new() | |
$contentList = [System.Collections.Generic.List[System.Collections.Generic.Dictionary[System.String,System.String]]]::new() | |
foreach ($moduleName in ($powerShellModules | Select-Object -Property Name -Unique).Name) | |
{ | |
$module = $powerShellModules.Where({$_.Name -eq $moduleName}) | Sort-Object -Property Version -Descending | Select-Object -First 1 | |
$contentDictionary = [System.Collections.Generic.Dictionary[System.String,System.String]]::new() | |
$contentDictionary.Add('ModuleName', $moduleName) | |
$contentDictionary.Add('ModuleVersion', $module.Version) | |
$contentDictionary.Add('Path', $module.Path) | |
$null = $contentList.Add($contentDictionary) | |
} | |
$inventoryItem = [Amazon.SimpleSystemsManagement.Model.InventoryItem]::new() | |
$inventoryItem.CaptureTime = $date | |
$inventoryItem.Content = $contentList | |
$inventoryItem.SchemaVersion = '1.0' | |
$inventoryItem.TypeName = 'Custom:PowerShellModule' | |
$null = $inventoryItems.Add($inventoryItem) | |
Write-SSMInventory -InstanceId $managedInstanceId -Item $inventoryItems |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment