代码之家  ›  专栏  ›  技术社区  ›  ExploringApple

Powershell脚本在服务器上工作,但不与cloudformation cfn init函数配合使用

  •  0
  • ExploringApple  · 技术社区  · 8 年前

    我有一些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

    1 回复  |  直到 8 年前
        1
  •  0
  •   ExploringApple    8 年前

    我能自己解决这个问题。从网站复制粘贴到编辑器时出现问题。粘贴时出现了一些奇怪的字符,在编辑器中无法看到。 诀窍在于 cat <file_name> 在PowerShell CLI中。它将显示外来字符(如果有)。