【发布时间】:2019-12-22 00:28:06
【问题描述】:
PowerShell 在 Az.Accounts 库中具有出色的功能 - “Connect-AzAccount” - 它允许我针对我的 Azure 实例进行身份验证并轻松发布 APIM。我需要将代码移植到 c# 并且找不到简单的等价物。
有没有人找到一个简单的方法来做到这一点? Azure 世界/库似乎经常更新,以及许多安全方面。很难找到最近的相关示例。
我的最终目标是针对 Azure 进行身份验证,然后将 API 发布到 API 网关。
PowerShell 代码:
$user = "account@domain.com"
$password = ConvertTo-SecureString -String "password goes here" -AsPlainText -Force
$azAccount = @{
subscription = "subscription-guid-goes-here"
credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $user,$password
}
Connect-AzAccount @azAccount
【问题讨论】:
-
Azure REST API 有一个 .NET Library,但我从未使用过它,所以在这里不能说它是否是一个可行的选择。您可以将代码保存到脚本中,然后通过将其传递给
PowerShell.exe从 C# 间接执行它。或者,您可以使用 PowerShell Class 更直接地调用 PowerShell。
标签: c# azure powershell azure-api-management azure-authentication