Skip to content

Instantly share code, notes, and snippets.

@danwagoner
Created January 17, 2019 18:02
Show Gist options
  • Save danwagoner/1ae19b9062a02ef06eeaaa5820cbb321 to your computer and use it in GitHub Desktop.
Save danwagoner/1ae19b9062a02ef06eeaaa5820cbb321 to your computer and use it in GitHub Desktop.
[Convert PS Script to SSM Document] Automatically generates the document json from provided script and saves the document in the documents folder. #powershell #ssm #aws
# Automatically generates the document json from provided script and saves the document in the documents folder.
param (
[Parameter(Mandatory=$True)]
[string]$ScriptPath,
[Parameter(Mandatory=$True)]
[string]$Description
)
$Prefix = @"
{
"schemaVersion": "1.2",
"description": "$($Description)",
"runtimeConfig": {
"aws:runPowerShellScript": {
"properties": [
{
"id": "0.aws:runPowerShellScript",
"timeoutSeconds": "7200",
"runCommand":
"@
$Suffix = @"
}
]
}
}
}
"@
If ((Test-Path $ScriptPath)) {
$JsonCode = Get-Content $($ScriptPath) | ForEach-Object { "$($_)".ToString() } | ConvertTo-Json
$Prefix + $JsonCode + $Suffix | Out-File "./documents/$((Get-ChildItem $ScriptPath).BaseName.ToLower()).json" -Encoding ASCII
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment