azure - Azure 自动化 - 身份验证循环
问题描述
Azure 自动化 Powershell 工作流有一个主要问题。我有一个工作流程负责删除超过 48 小时的快照。出于某种原因,当工作流运行时,当它在一次运行期间多次向 Azure 进行身份验证时,我最终会出现一个循环。
所有模块都是最新的。
这是代码:
workflow Auto-Snapshot-Cleanup
{
#Authentication
Write-Output ""
Write-Output "------------------------ Authentication ------------------------"
Write-Output "Logging into Azure ..."
Clear-AzContext -Force
try{
# Ensures you do not inherit an AzContext in your runbook
$null = Disable-AzContextAutosave -Scope Process
$Conn = Get-AutomationConnection -Name AzureRunAsConnection
$null = Connect-AzAccount `
-ServicePrincipal `
-Tenant $Conn.TenantID `
-ApplicationId $Conn.ApplicationID `
-CertificateThumbprint $Conn.CertificateThumbprint
Write-Output "Successfully logged into Azure."
}
catch{
if (!$conn){
$ErrorMessage = "Service principal not found."
throw $ErrorMessage
}
else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
## End of authentication
## Getting all Resource Groups in the Test spoke
Write-Output ""
Write-Output ""
Write-Output "---------------------------- Status ----------------------------"
Write-Output "Getting all Resource Groups in the Test spoke ..."
try{
$groups = Get-AzResourceGroup
foreach -parallel ($group in $groups){
#Delete snapshots older than 48 hours
$snapshotList = Get-AzSnapshot -ResourceGroupName $using:group.ResourceGroupName | Where-Object {$_.Name -like 'autosnapshot*'}
$snapage = 48
foreach -parallel ($snap in $snapshotList){
InlineScript{
try{
$start = $using:snap.TimeCreated
$deletedsnap = $using:snap.name
if (!((New-TimeSpan -Start ($start).AddHours(2) -End (get-date).ToString() ).TotalHours -lt $using:SnapAge)){
#Write-Output "Removing $deletedsnap"
Remove-AzSnapshot -SnapshotName $using:snap.Name -ResourceGroupName $using:snap.ResourceGroupName -Force
}
}
catch{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
}
}
}
catch{
Write-Error -Message $_.Exception
throw $_.Exception}
}
结果是这样的:
任何帮助将不胜感激。亲切的问候,沃伊切赫
解决方案
推荐阅读
- react-native - 使用 Google App Signing 在 Android 上发布 Expo 已损坏
- sql - 检索不共享密钥的 JSON 元素
- android - 模拟器:模拟器:错误:找不到模拟器可执行文件。模拟器:进程以退出代码-1完成
- c# - 不能同时旋转和移动
- grails - 库不匹配(quartz、activiti-engine、usertype.jodatime、grails-shiro)
- sql - 用于大临时数据的 Nosql 或 sql 数据库
- java - Android java,数据库类中的Dao接口似乎很奇怪
- c - 如何区分 C 代码中的 armhf (ARMv7) 和 armel (ARMv4)?
- python - 将裁剪图像的文件夹填充到最大宽度
- php - 在按钮中使用 slug 功能,但 div 代码下方的按钮被隐藏