嗨,我是在 azure 中运行 powershell 脚本并寻找最佳指导的新手?
我创建了一个 powershell 脚本来定位资源组中正在运行的机器并输出到一个文本文件,
安排此脚本在 azure 中自主运行的最佳方法是什么?
下面的脚本:
#Login-AzureRmAccount
#$sub = Get-AzureRmSubscription | Out-GridView -PassThru | Set-AzureRmContext
$path="dcsppomsstorage.blob.core.windows.net/dcsvmpowerstate/activeserver1.txt"
function SPWservers {
[string]$ResourceGroupName = "*DCS-PP*"
$VMresourcegroups = (Get-AzureRmResourceGroup).Where({$_.ResourceGroupName -like $ResourceGroupName})
foreach($VMresourcegroup in $VMresourcegroups){
$vms=Get-AzureRmVM -ResourceGroupName $VMresourcegroup.ResourceGroupName
foreach ($vm in $vms)
{
$Status = (get-azurermvm -ResourceGroupName $VMresourcegroup.ResourceGroupName -Name $vm.Name -Status).Statuses
Write "powerstate for $($vm.Name) is $($Status[1].DisplayStatus)" | Format-Table $vm.Name, $Status[1].DisplayStatus -GroupBy $vm.name
}
}
}
SPWservers| out-file $path