Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
命令行包含空间时,带参数的Powershell中的AWS CLI AWS RunRemoteScript返回错误_Powershell_Amazon Ec2_Aws Cli - Fatal编程技术网

命令行包含空间时,带参数的Powershell中的AWS CLI AWS RunRemoteScript返回错误

命令行包含空间时,带参数的Powershell中的AWS CLI AWS RunRemoteScript返回错误,powershell,amazon-ec2,aws-cli,Powershell,Amazon Ec2,Aws Cli,我的目标是使用PowerShell自动化一些AWS流程 其中一个步骤是从远程位置(在我的例子中是S3)在EC2 Windows机器上执行ps1脚本 问题是脚本必须使用强制参数运行。每当命令包含空格时,CLI将抛出: aws ssm发送命令——区域us-west-2——目标键=tag:T,值=V——文档名“aws RunRemoteScript”--参数“{\”sourceType\”:[\“S3\”],\“sourceInfo\”:[\“{\\\\”路径\\”:\\”https://bucket

我的目标是使用PowerShell自动化一些AWS流程

其中一个步骤是从远程位置(在我的例子中是S3)在EC2 Windows机器上执行ps1脚本

问题是脚本必须使用强制参数运行。每当命令包含空格时,CLI将抛出:

aws ssm发送命令——区域us-west-2——目标键=tag:T,值=V——文档名“aws RunRemoteScript”--参数“{\”sourceType\”:[\“S3\”],\“sourceInfo\”:[\“{\\\\”路径\\”:\\”https://bucketName.s3-us-west-2.amazonaws.com/folder/Install.ps1\\\“}\”],\“命令行\:[\”\\Install.ps1-Param1 value\“]}'

返回

aws : usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
At line:1 char:1
+ aws ssm send-command --region us-west-2 --targets Key=tag:T,Values=V  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (usage: aws [opt....] [parameters]:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

To see help text, you can run:
  aws help
  aws <command> help
  aws <command> <subcommand> help
Unknown options: -Param1, value"]}
aws:用法:aws[选项][…][参数]
第1行字符:1
+aws ssm发送命令--区域us-west-2--目标键=标记:T,值=V。。。
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+CategoryInfo:NotSpecified:(用法:aws[opt….][parameters]:字符串)[],RemoteException
+FullyQualifiedErrorId:NativeCommandError
要查看帮助文本,您可以运行:
aws帮助
aws帮助
aws帮助
未知选项:-Param1,值“]}
而不使用
-Param1值时
工作正常。 甚至在“命令行”的末尾添加一个空格也会导致这个问题

…\“commandLine\”:[\“\\Install.ps1\”]}
结果带有
…未知选项:“%]}

我怀疑这是某种PowerShell语法/转义问题,因为相同的命令(带有正确的转义)在bash控制台上工作


参考bash shell上的it应该可以工作,但我在powershell中找不到任何工作示例…

以下是bash shell中的工作示例:
aws ssm send命令--region us-west-2--targets Key=tag:t,Values=V--文档名“aws RunRemoteScript”--参数“{”sourceType:[“S3”],“sourceInfo:[“{”path\:\”https://bucketNameXX.s3-us-west-2.amazonaws.com/folder/Install.ps1\“}”],“命令行”:[“.Install.ps1-Param1 value”]}'

删除了所有转义,但双引号insight“sourceInfo”值除外

$aws ssm send-command --region us-west-2 --targets Key=tag:T,Values=V --document-name "AWS-RunRemoteScript" --parameters '{"sourceType":["S3"],"sourceInfo":["{\"path\":\"https://bucketName.s3-us-west-2.amazonaws.com/folder/Install.ps1\"}"],"commandLine":[".Install.ps1 -Param1 value"]}'

{
    "Command": {
        "CommandId": "f1924381-b50c-4a23-a0b5-xxxxxxxxxxxx",
        "DocumentName": "AWS-RunRemoteScript",
        "DocumentVersion": "",
        "Comment": "",
        "ExpiresAfter": 1584737377.038,
        "Parameters": {
            "commandLine": [
                ".Install.ps1 -Param1 value"
            ],
            "sourceInfo": [
                "{\"path\":\"https://bucketNameXX.s3-us-west-2.amazonaws.com/folder/Install.ps1\"}"
            ],
            "sourceType": [
                "S3"
            ]
        },
        "InstanceIds": [],
        "Targets": [
            {
                "Key": "tag:T",
                "Values": [
                    "V"
                ]
            }
        ],
        "RequestedDateTime": 1584730177.038,
        "Status": "Pending",
        "StatusDetails": "Pending",
        "OutputS3BucketName": "",
        "OutputS3KeyPrefix": "",
        "MaxConcurrency": "50",
        "MaxErrors": "0",
        "TargetCount": 0,
        "CompletedCount": 0,
        "ErrorCount": 0,
        "DeliveryTimedOutCount": 0,
        "ServiceRole": "",
        "NotificationConfig": {
            "NotificationArn": "",
            "NotificationEvents": [],
            "NotificationType": ""
        },
        "CloudWatchOutputConfig": {
            "CloudWatchLogGroupName": "",
            "CloudWatchOutputEnabled": false
        }
    }
}