【发布时间】:2021-02-08 12:35:36
【问题描述】:
我想获取禁用了自动关闭的 azure 服务器列表,我有以下脚本,但脚本的问题是它获取订阅 GUID 下的 RG 列表,但在每个循环后重复输出.
Import-AzureRmContext -Path "$PSScriptRoot\AzureProfile.json"
Select-AzureRmSubscription -SubscriptionId {subscriptionId}
[array]$ResourceGroupArray = Get-AzureRMVm | Select-Object -Property ResourceGroupName, Name, VmId
foreach ($resourceGroup in $ResourceGroupArray){
$targetResourceId = (Get-AzureRmVM -ResourceGroupName $resourcegroup.ResourceGroupName -Name $resourceGroup.Name).Id
$shutdownInformation = (Get-AzureRmResource -ResourceGroupName $resourcegroup.ResourceGroupName -ResourceType Microsoft.DevTestLab/schedules -Expandproperties).Properties
Write-Host "ID: " $targetResourceId
$shutdownInformation
每个 VM 的输出以以下格式显示,
我想要的很简单,我希望 VM 名称及其自动关闭状态显示在屏幕上,以便我轻松找出哪些所有 VM 当前已禁用自动关闭。
任何与此相关的帮助都会有所帮助。
【问题讨论】:
标签: azure powershell azure-powershell powershell-4.0 azure-rm