gpt4 book ai didi

visual-studio - 通过 Visual Basic 将 Set-AWScredential 与 PS 结合使用

转载 作者:行者123 更新时间:2023-12-05 07:04:14 25 4
gpt4 key购买 nike

所以我尝试使用管道创建一些 aws 配置文件以打开 powershell 并运行命令。当我直接通过 PS 使用命令时它工作得很好但是当尝试使用管道时它只是说命令不存在:

术语“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”类型的未处理异常未找到方法:'Void 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)

关于visual-studio - 通过 Visual Basic 将 Set-AWScredential 与 PS 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62984990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com