powershell - Azure 凭据尚未设置或已过期

标签 powershell azure

我已安排一个 PowerShell 脚本来执行 Azure 中的管道。 已使用 Login-AzureRMAccount 生成登录脚本(ProfileContext.ctx)

下面是要安排的代码:

$path = "D:\ProfileContext.ctx"
Import-AzureRmContext -Path $path
$dfn = "salesprod"
$rgn = "sale-dw"
$df=Get-AzureRmDataFactory -ResourceGroupName $rgn -Name $dfn

$ISTstartdate = get-date

#Set Pipeline active period
$UTCstartdate = $ISTstartdate.touniversaltime().addminutes(5)
$UTCenddt = $UTCstartdate.AddHours(5)

$pipelinename = "SalesPipeline"

Set-AzureRmDataFactoryPipelineActivePeriod -ResourceGroupName $rgn -PipelineName $pipelinename -DataFactoryName $dfn -StartDateTime $UTCstartdate -EndDateTime $UTCenddt -Force 

上面的代码可以正常工作 2 或 3 天,但随后我开始遇到以下问题:

您的 Azure 凭据尚未设置或已过期,请运行 Login-AzureRMAccount 来设置您的 Azure 凭据。 在 D:\RunPipeline.ps1 以下是版本号:

  1. PS 版本 - 5.0.10586.117
  2. Azure - 4.2.1

最佳答案

我通过使用以下解决方法解决了这个问题:这将为我自动登录,然后我可以在没有上下文文件的情况下进行安排:

$accountName = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5b2b2a291b23222175383436" rel="noreferrer noopener nofollow">[email protected]</a>"
$password = ConvertTo-SecureString "mypwd" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($accountName, $password)
Login-AzureRmAccount -Credential $credential
Get-AzureRmResource 

关于powershell - Azure 凭据尚未设置或已过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46089692/

相关文章:

powershell - 如何在 Write-Host 中使用十六进制颜色代码?

windows - 如何静默安装RabbitMq

Powershell将参数值传递给参数并返回

c# - 无法从 .NET 连接器连接到 Azure MySQL 数据库

Azure Databricks 作业通知电子邮件

xml - 并非所有 XML 属性都通过管道传递

azure - 如何将自定义域与 Azure 容器应用程序一起使用?

Silverlight clientaccesspolicy.xml 和 Azure 开发存储

Azure Web App - 无法加载文件或程序集 Microsoft.SqlServer.Types

.net - 如何从 powershell 打开 Excel 工作簿以实现自动化