get csv output in diff columns

 

Hi Guys,

 

below script gives me out put of tags in csv in below format (all values and keys in a single column)

 

VALUE1:VALUE2:VALUE3:KEY1:KEY2:KEY3
How do I change that to get get in below format (values and key in separate columns)? <colgroup><col style="width: 48pt;" span="6" width="64" /> </colgroup>
VALUE1 KEY1 VALUE2 KEY2 VALUE3 KEY3
 

 

$subs = Get-AzureRmSubscription

$allResources = @()

foreach ($sub in $subs) 
{
Select-AzureRmSubscription -SubscriptionId $sub.SubscriptionId
$resources = Get-AzureRmResource
foreach ($resource in $resources)
{
$customPsObject = New-Object -TypeName PsObject
$subscription = Get-AzureRmSubscription -SubscriptionId $resource.SubscriptionId
$tags = $resource.Tags.Keys + $resource.Tags.Values -join ':'

$customPsObject | Add-Member -MemberType NoteProperty -Name ResourceName -Value $resource.Name
$customPsObject | Add-Member -MemberType NoteProperty -Name ResourceGroup -Value $resource.ResourceGroupName
$customPsObject | Add-Member -MemberType NoteProperty -Name ResourceType -Value $resource.ResourceType
$customPsObject | Add-Member -MemberType NoteProperty -Name Kind -Value $resource.Kind
$customPsObject | Add-Member -MemberType NoteProperty -Name Location -Value $resource.Location
$customPsObject | Add-Member -MemberType NoteProperty -Name Tags -Value $tags
$customPsObject | Add-Member -MemberType NoteProperty -Name Sku -Value $resource.Sku
$customPsObject | Add-Member -MemberType NoteProperty -Name ResourceId -Value $resource.ResourceId
$customPsObject | Add-Member -MemberType NoteProperty -Name Subscription -Value $subscription.Name
$allResources += $customPsObject

}

}


$allResources | Export-Csv -Path C:\temp\resource-audit.csv -NoTypeInformation

I think you are missing something. What command is giving you the output with ‘:’ ?
You are doing a join operation with ‘:’ . I didn’t get your expectation about ‘keys and values in separate columns’

Hi Soma - it works like this…

[pre]

$tags = $resource.Tags.Keys | foreach {($, $resource.Tags[$]) -join “:”}

[/pre]