Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save peacengell/24e015eb5319ac57b5785fc0a9fef66c to your computer and use it in GitHub Desktop.
Save peacengell/24e015eb5319ac57b5785fc0a9fef66c 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