Export Azure VM details to CSV with Tags

Import-Module -Name Az

Login-AzAccount

get-azsubscription
$getallSubscriptions = Get-AzSubscription

foreach($subscription in $getallSubscriptions)
{
Select-AzSubscription $subscription$vms = Get-AzVM
foreach($vm in $vms)
{

{$TagOut =$nulll

foreach($tag in $vm.tags.keys)
{
$Tagz=$tag+ ":" + $vm.tags.$tag+ ","
$TagOut=$TagOut+$Tagz
}  $value = $($subscription.Id) + "," + $($rg.ResourceGroupName)  + "," + $vm.Name + ","  + "," +$vm.Id + "," + $TagOut 

Add-content -path "C:\azure-Vm.txt" -value $value

$TagOut will have the complete tags with comma separated


you can rename the output file to csv and make use of it 


Comments

Popular posts from this blog

Find the Vnet details of an Azure VM -Powershell