我有一些powershell脚本,可以添加标签并将磁盘驱动器格式化为特定格式。
问题是,当从cloudformation cfn函数调用此powershell脚本时,它会产生类似错误(来自日志)
a-label-format-drives-sql output: At C:\cfn\scripts\Label-and-Format-drives.ps1:44 char:35
+ $ErrorActionPreference = "Stop"
+ ~
The string is missing the terminator: ".
At C:\cfn\scripts\Label-and-Format-drives.ps1:36 char:5
+ {
+ ~
Missing closing '}' in statement block.
At C:\cfn\scripts\Label-and-Format-drives.ps1:27 char:19
+ $LablenFormatPs={
+ ~
Missing closing '}' in statement block.
At C:\cfn\scripts\Label-and-Format-drives.ps1:19 char:5
+ try {
+ ~
Missing closing '}' in statement block.
At C:\cfn\scripts\Label-and-Format-drives.ps1:64 char:1
+
The Try statement is missing its Catch or Finally block.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
但是,当同一个脚本直接在同一个windows ec2的powershell控制台中运行时,它运行得非常好。我将这个poweshell脚本上传到s3 bucket中,我将在cloudformation中获取它,并将其保存在ec2实例上。
这是我的完整脚本。
https://gist.github.com/rturam/c969e161b4089ac62d89b8ba5d1d1612