简体   繁体   English

Powershell脚本可在服务器上运行,但不能与cloudformation cfn-init函数一起使用

[英]Powershell script works on server but not with cloudformation cfn-init functions

I have to set windows ec2 servers through cloudformation script. 我必须通过cloudformation脚本设置Windows ec2服务器。 I have some powershell script which add label and format the disk drives in specific format. 我有一些powershell脚本,可以添加标签并以特定格式格式化磁盘驱动器。

The problem is when this powershell script get called from cloudformation cfn functions it gives error like (from LOGS) 问题是,当从cloudformation cfn函数调用此powershell脚本时,它给出了类似的错误(来自LOGS)

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

But when the same script is directly run in powershell console in same windows ec2 it runs perfectly fine. 但是,当同一脚本在同一Windows ec2中的Powershell控制台中直接运行时,它运行得很好。 I have this poweshell script uploaded in to s3 bucket and I am fetching it in cloudformation and saving it on ec2 instances. 我已将此poweshell脚本上传到s3存储桶中,并以cloudformation的形式获取它并将其保存在ec2实例上。

Here is my complete script. 这是我完整的脚本。 https://gist.github.com/rturam/c969e161b4089ac62d89b8ba5d1d1612 https://gist.github.com/rturam/c969e161b4089ac62d89b8ba5d1d1612

I am able to solve this issue myself. 我自己就能解决这个问题。 There was a problem with copy-paste from website to editor. 从网站复制到编辑器时出现问题。 While pasting there was some strange characters come along and were not viewable in an editor. 粘贴时会出现一些奇怪的字符,这些字符在编辑器中无法查看。 The trick is just doing cat <file_name> in PowerShell CLI. 诀窍只是在PowerShell CLI中执行cat <file_name> It will show the foreign characters if any. 如果有,它将显示外来字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM