因此,我试图使用管道打开Powershell并运行命令来创建一些aws配置文件。当我直接通过PS使用命令时,它可以完美工作,但是当尝试使用Pipeline时,它只是说该命令不存在:
术语“ Set-AWSCredential”不被视为cmdlet,函数,脚本文件或可操作程序的名称。检查名称的拼写,或者是否包含路径,请验证路径是否正确,然后重试。
这是我正在使用的代码:
Dim accessKey = accessKeyTxt.Text()
Dim secretKey = secretAccessTxt.Text()
Dim profileName = profileNameTxt.Text()
Dim runspace As Runspace = RunspaceFactory.CreateRunspace()
runspace.Open()
Dim pipeline As Pipeline = runspace.CreatePipeline()
pipeline.Commands.AddScript("Set-AWSCredential -ProfileLocation $env:USERPROFILE\.aws\credentials -StoreAs " & profileName & " -AccessKey " & accessKey & " -SecretKey " & secretKey)
pipeline.Commands.Add("Out-String")
pipeline.Invoke()
runspace.Close()
在这一点上,我不知道是否有可能实现这一目标。任何帮助。
编辑#1:
因此,我通过导入AWS.Tools.Common来绕过此操作:
Dim pipeline As Pipeline = runspace.CreatePipeline()
pipeline.Commands.AddScript("Set-ExecutionPolicy RemoteSigned")
pipeline.Commands.Add("Out-String")
pipeline.Invoke()
Dim pipeline2 As Pipeline = runspace.CreatePipeline()
pipeline2.Commands.AddScript("Import-module AWS.Tools.Common")
pipeline2.Commands.Add("Out-String")
pipeline2.Invoke()
Dim pipeline3 As Pipeline = runspace.CreatePipeline()
pipeline3.Commands.AddScript("Set-AWSCredential -ProfileLocation $env:USERPROFILE\.aws\credentials -StoreAs test100 -AccessKey test1 -SecretKey test1")
pipeline3.Commands.Add("Out-String")
pipeline3.Invoke()
现在它找到了脚本,但是我得到了一个空方法错误:
引发的异常:System.Management.Automation.dll中的“ System.Management.Automation.CmdletInvocationException” System.Management.Automation.dll中发生了类型为“ System.Management.Automation.CmdletInvocationException”的未处理异常,未找到方法:“无效的Amazon” .Runtime.AssumeRoleAWSCredentialsOptions.set_ProxySettings(System.Net.IWebProxy)'。
我不知道该如何解决。
所以我只是放弃了,并以简单的方式做到了。
Dim accessKey = accessKeyTxt.Text()
Dim secretKey = secretAccessTxt.Text()
Dim profileName = profileNameTxt.Text()
Dim awsPath = Environment.GetEnvironmentVariable("USERPROFILE")
Dim inputString As String = "
[" & profileName & "]
aws_access_key_id=" & accessKey & "
aws_secret_access_key=" & secretKey & "
region=us-east-1
"
My.Computer.FileSystem.WriteAllText("" & awsPath & "\.aws\credentials", inputString, True)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句