Amazon web services 作为用户数据中的另一个用户调用脚本时出现问题

Amazon web services 作为用户数据中的另一个用户调用脚本时出现问题,amazon-web-services,powershell,amazon-ec2,Amazon Web Services,Powershell,Amazon Ec2,目前,我在用户数据中加载了以下脚本 $username = "ABC" $Password = ConvertTo-SecureString -AsPlainText -String "xxx" -Force $credential = New-Object System.Management.Automation.PSCredential $username, $Password Start-Process -FilePath "powersh

目前,我在用户数据中加载了以下脚本

$username = "ABC"
$Password = ConvertTo-SecureString -AsPlainText -String "xxx" -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $Password
Start-Process -FilePath "powershell" -Credential $credential -WorkingDirectory "C:\Test" -ArgumentList @(".\script.ps1") -Wait
但是,似乎没有执行script.ps1。没有错误或输出。它就是不起作用。脚本仅在实例本身中执行时有效,而在实例启动和调用用户数据时无效

更新: script.ps1的目的是返回一个文本文件,该文件显示用户执行script.ps1的内容。因此,执行用户数据后的预期输出将是一个文本文件,但事实并非如此

Script.ps1

([Environment]::UserDomainName+“”++[Environment]::UserName)|输出文件test.txt “$env:userdomain$env:username”|输出文件-append test.txt
[Security.Principal.WindowsIdentity]::GetCurrent().Name | out file-append test.txt

什么让你认为它不起作用?script.ps1做什么?另外,由于您正在将工作目录设置为C:\Test,因此script.ps1应该作为“.”的位置将是工作目录。请尝试
启动进程-FilePath“powershell”-Credential$Credential-WorkingDirectory“C:\Test”-ArgumentList“-NoExit”,“-File`”C:\fullPath\to\script.ps1`
。如果这不起作用,我们需要更多的细节来理解“不被执行”是什么意思。另外,为
script.ps1
添加代码可以帮助我们了解问题可能是什么。