概述
ARM Mode
$loglog=@()
Add-AzureRmAccount -EnvironmentName AzureChinaCloud
$SubscriptionNames = Get-AzureRMSubscription
foreach (
subin
SubscriptionNames)
{
Select-AzureRMSubscription -SubscriptionName $sub.Name
Write-Output "Processing " $sub.Name
$vmlist = Get-AzureRMVM
foreach ($vm in $vmlist)
{
$vmStatus = Get-AzureRMVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name -Status
$displayStatus = $vmStatus.Statuses.DisplayStatus[1]
$output = new-object PSObject
$output | add-member -Membertype NoteProperty -Name "Mode" -value "ARM"
$output | add-member -Membertype NoteProperty -Name "SubscriptioName" -value "$($sub.Name)"
$output | add-member -Membertype NoteProperty -Name "ResourceGroupName" -value "$($vm.ResourceGroupName)"
$output | add-member -Membertype NoteProperty -Name "VMName" -value "$($vm.Name)"
$output | add-member -Membertype NoteProperty -Name "OSType" -value "$($vm.StorageProfile.OsDisk.OsType)"
$output | add-member -Membertype NoteProperty -Name "VMSize" -value "$($vm.HardwareProfile.VmSize)"
$output | add-member -Membertype NoteProperty -Name "VMStatus" -value "$($displayStatus)"
if($vm.AvailabilitySetReference.Id)
{
$avSetName = $vm.AvailabilitySetReference.Id.Split("/")[-1]
}
else
{
$avSetName = "NULL"
}
$output | add-member -Membertype NoteProperty -Name "AvailabilitySetName" -value "$($avSetName)"
#
$isCustomerInitiatedMaintenanceAllowed = "False"
$preMaintenanceWindowStartTime = "NULL"
$preMaintenanceWindowEndTime = "NULL"
$maintenanceWindowStartTime = "NULL"
$maintenanceWindowEndTime = "NULL"
$lastOperationResultCode = "NULL"
$lastOperationMessage = "NULL"
if($vmStatus.MaintenanceRedeployStatus)
{
$isCustomerInitiatedMaintenanceAllowed= $vmStatus.MaintenanceRedeployStatus.IsCustomerInitiatedMaintenanceAllowed
$preMaintenanceWindowStartTime= $vmStatus.MaintenanceRedeployStatus.PreMaintenanceWindowStartTime
$preMaintenanceWindowEndTime= $vmStatus.MaintenanceRedeployStatus.PreMaintenanceWindowEndTime
$maintenanceWindowStartTime= $vmStatus.MaintenanceRedeployStatus.MaintenanceWindowStartTime
$maintenanceWindowEndTime= $vmStatus.MaintenanceRedeployStatus.MaintenanceWindowEndTime
$lastOperationResultCode= $vmStatus.MaintenanceRedeployStatus.LastOperationResultCode
$lastOperationMessage= $vmStatus.MaintenanceRedeployStatus.LastOperationMessage
}
$output | add-member -Membertype NoteProperty -Name "IsCustomerInitiatedMaintenanceAllowed" -value "$($IsCustomerInitiatedMaintenanceAllowed)"
$output | add-member -Membertype NoteProperty -Name "PreMaintenanceWindowStartTime" -value "$($PreMaintenanceWindowStartTime)"
$output | add-member -Membertype NoteProperty -Name "PreMaintenanceWindowEndTime" -value "$($PreMaintenanceWindowEndTime)"
$output | add-member -Membertype NoteProperty -Name "MaintenanceWindowStartTime" -value "$($MaintenanceWindowStartTime)"
$output | add-member -Membertype NoteProperty -Name "MaintenanceWindowEndTime" -value "$($MaintenanceWindowEndTime)"
$output | add-member -Membertype NoteProperty -Name "LastOperationResultCode" -value "$($LastOperationResultCode)"
$output | add-member -Membertype NoteProperty -Name "LastOperationMessage" -value "$($LastOperationMessage)"
$loglog += $output
}
}
Write-Output “ARM is Done, prepare for ASM”
ASM Mode
Add-AzureAccount -Environment AzureChinaCloud
$SubscriptionNames = Get-AzureSubscription
foreach (
subin
SubscriptionNames)
{
Select-AzureSubscription -SubscriptionName $sub.SubscriptionName -Current
Write-Output "Processing " $sub.SubscriptionName
$vmlist = get-azureVM
foreach($vm in $vmlist)
{
$vmstatus = $vm.status
$output = new-object PSObject
$output | add-member -Membertype NoteProperty -Name "Mode" -value "ASM"
$output | add-member -Membertype NoteProperty -Name "SubscriptioName" -value $sub.SubscriptionName
$output | add-member -Membertype NoteProperty -Name "ResourceGroupName" -value "ASM Default Resource Group"
$output | add-member -Membertype NoteProperty -Name "VMName" -value "$($vm.name)"
$output | add-member -Membertype NoteProperty -Name "OSType" -value "$($vm.VM.OSVirtualHardDisk.OS)"
$output | add-member -Membertype NoteProperty -Name "VMSize" -value "$($vm.InstanceSize)"
$output | add-member -Membertype NoteProperty -Name "VMStatus" -value "$($vmstatus)"
$output | add-member -Membertype NoteProperty -Name "AvailabilitySetName" -value "$($vm.AvailabilitySetName)"
$output | add-member -Membertype NoteProperty -Name "IsCustomerInitiatedMaintenanceAllowed" -value "$($IsCustomerInitiatedMaintenanceAllowed)"
$output | add-member -Membertype NoteProperty -Name "PreMaintenanceWindowStartTime" -value "$($PreMaintenanceWindowStartTime)"
$output | add-member -Membertype NoteProperty -Name "PreMaintenanceWindowEndTime" -value "$($PreMaintenanceWindowEndTime)"
$output | add-member -Membertype NoteProperty -Name "MaintenanceWindowStartTime" -value "$($MaintenanceWindowStartTime)"
$output | add-member -Membertype NoteProperty -Name "MaintenanceWindowEndTime" -value "$($MaintenanceWindowEndTime)"
$output | add-member -Membertype NoteProperty -Name "LastOperationResultCode" -value "$($LastOperationResultCode)"
$output | add-member -Membertype NoteProperty -Name "LastOperationMessage" -value "$($LastOperationMessage)"
$loglog += $output
}
}
$loglog | convertto-Csv -NoTypeInformation | out-file D:azureVMList.csv -append -Encoding utf8
Write-Output “Export Success, please check azureacl file in Disk D:”
最后
以上就是忧心钢笔为你收集整理的批量导出Azure所有虚拟机信息ARM ModeASM Mode的全部内容,希望文章能够帮你解决批量导出Azure所有虚拟机信息ARM ModeASM Mode所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复