Created
January 17, 2019 18:02
-
-
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
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
# 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