我正在做一些清单,试图从Azure收集我所有的启动/停止VM计划。 我正在努力提取为每周重复计划选择的日期。 我可以使用以下方法从单个日程表中提取所有数据:
Select-AzureRmSubscription <name>
$schedule = Get-AzureRmAutomationSchedule -AutomationAccountName <name)-ResourceGroupName <name> -Name <name>
然后得到所有的日子:
$schedule.WeeklyScheduleOptions.DaysOfWeek -join ","
哪个输出:星期一,星期二,星期三,星期四,星期五
但是如果我遍历所有订阅并构建psobject 对于所有计划数据,该数据为空:
$AzSubs = Get-AzureRmSubscription
$objs = @()
foreach ($AzSub in $AzSubs){
Get-AzureRmSubscription -SubscriptionName $AzSub.Name | Select-AzureRmSubscription
$azAutAccs = Get-AzureRmAutomationAccount
foreach ($azAutAcc in $azAutAccs){
$AzAutScheds = Get-AzureRmAutomationSchedule -AutomationAccountName $azAutAcc.AutomationAccountName -ResourceGroupName $azAutAcc.ResourceGroupName
$AzAutScheds = $AzAutScheds | where{$_.IsEnabled -eq "True"}
foreach ($AzAutSched in $AzAutScheds){
$DOW = $azAutSched.WeeklyScheduleOptions.DaysOfWeek -join "," | out-string
$DOM = $azAutSched.MonthlyScheduleOptions.DaysOfMonth -join "," | out-string
$obj = new-object psobject -Property @{
SchedName = $AzAutSched.Name
LastModifiedTime = (get-date ([DateTime]::Parse($AzAutSched.LastModifiedTime)) -Format "dd-MM-yyyy HH:mm (zzz)")
IsEnabled = $AzAutSched.IsEnabled
AutomationAccount = $azAutAcc.AutomationAccountName
ResourceGroup = $azAutAcc.ResourceGroupName
NextRun = ([DateTime]::Parse($azAutSched.NextRun))
StartTime = (get-date ([DateTime]::Parse($azAutSched.StartTime)) -Format "HH:mm (zzz)")
TimeZone = $azAutSched.TimeZone
Interval = $azAutSched.Interval
Frequency = $azAutSched.Frequency
WeekSchedule = $DOW
MonthSchedule = $DOM
}
$objs += $obj
}
}
}
$objs | sort SchedName | ft -Property SchedName,LastModifiedTime,StartTime,TimeZone,Interval,Frequency,WeekSchedule,MonthSchedule
然后我的表最后只有WeekSchedule / MonthSchedule的空白列。
我尝试了不同的组合,包括不使用out-string参数,不使用join,直接在属性行中设置属性,以及如引用那样在对象上方构建变量并在属性行上引用它。他们都不起作用。
任何人都可以了解我所缺少的东西吗?或其他有关如何完成此操作的提示也非常受欢迎。
AzureRM模块是最新的。
答案 0 :(得分:0)
根据我的测试,您需要获取单独的日程表,而不是资源组中的所有日程表,在这种情况下,它将起作用:
foreach ($azAutAcc in $azAutAccs){
$AzAutScheds = Get-AzAutomationSchedule -AutomationAccountName $azAutAcc.AutomationAccountName -ResourceGroupName $azAutAcc.ResourceGroupName
$AzAutScheds = $AzAutScheds | Where-Object {$_.IsEnabled -eq "True"}
foreach ($AzAutSched in $AzAutScheds){
$AzAutSched = Get-AzAutomationSchedule -AutomationAccountName $azAutAcc.AutomationAccountName -ResourceGroupName $azAutAcc.ResourceGroupName -Name $AzAutSched.Name
$DOW = $azAutSched.WeeklyScheduleOptions.DaysOfWeek -join "," | out-string
$DOM = $azAutSched.MonthlyScheduleOptions.DaysOfMonth -join "," | out-string
$objs += new-object psobject -Property @{
SchedName = $AzAutSched.Name
LastModifiedTime = (get-date ([DateTime]::Parse($AzAutSched.LastModifiedTime)) -Format "dd-MM-yyyy HH:mm (zzz)")
IsEnabled = $AzAutSched.IsEnabled
AutomationAccount = $azAutAcc.AutomationAccountName
ResourceGroup = $azAutAcc.ResourceGroupName
NextRun = ([DateTime]::Parse($azAutSched.NextRun))
StartTime = (get-date ([DateTime]::Parse($azAutSched.StartTime)) -Format "HH:mm (zzz)")
TimeZone = $azAutSched.TimeZone
Interval = $azAutSched.Interval
Frequency = $azAutSched.Frequency
WeekSchedule = $DOW
MonthSchedule = $DOM
}
}
}