# Format output in single lines

**URL:** <https://forums.powershell.org/t/format-output-in-single-lines/19882>\
**Category:** PowerShell Help\
**Created:** [July 13, 2022, 6:53pm UTC](https://forums.powershell.org/t/format-output-in-single-lines/19882 "2022-07-13T18:53:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anelliaf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@anelliaf](https://forums.powershell.org/u/anelliaf)\
**Post date:** [July 13, 2022, 6:53pm UTC](https://forums.powershell.org/t/format-output-in-single-lines/19882/1 "2022-07-13T18:53:00Z")

</div>

The following code output is returning blank records as well as the records I’m looking for:

```auto
# Parameter prompting for Azure subscription
PARAM(
    [string] [Parameter(Mandatory = $True, HelpMessage = "Choose subscription you want be inventoried")] $SubscriptionName
    )

#Login to Azure
Connect-AzAccount
 
#Select Azure Subscription
Get-AzSubscription -SubscriptionName $SubscriptionName | Select-AzSubscription

$rg = Get-AzResourceGroup | ?{ $_.ProvisioningState -eq "succeeded" } | select -expandproperty resourcegroupname
$results = 
foreach ($resourcegroup in $rg)
{
    $azResource = Get-AzResource -ResourceGroupName $resourcegroup | ? {$_.Type -match "Microsoft.Sql"}

    [PSCustomObject]@{
                     #Subscription = $SubscriptionName
                     ResourceGroup = $azResource.ResourceGroupName
                     ResourceName = $azResource.Name
                     ResourceType = $azResource.ResourceType
                     #Location = $azResource.Location
                     }
}

# Return the results in table format
$results

```

However, the output is returning bunched up as well as blank lines:

```auto
ResourceGroup ResourceName
------------- ------------

{test1, test1, test1, test1...} {sim-data, sim-data/dac-sta, sim-data/master, sim-data/ddd-ddd...}
{test2, test2, test2, test2...} {tst-data, tst-data/dac-sta, tst-data/master, tst-data/ddd-ddd...}

```

I’d like for it return in tabular format but a line for each resource?

Thanks!

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [July 13, 2022, 9:51pm UTC](https://forums.powershell.org/t/format-output-in-single-lines/19882/2 "2022-07-13T21:51:14Z")

</div>

If the variable `$azResource` is an array and you should use another inner loop inside your existing loop to access the individual elements. You may _rename_ the to `$azResourceGroup`. Then you could actually keep the PSCustomObject creation inside the newly created loop. 😉

---

<div class="post-metadata">

**Author:** ![anelliaf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@anelliaf](https://forums.powershell.org/u/anelliaf)\
**Post date:** [July 14, 2022, 11:58am UTC](https://forums.powershell.org/t/format-output-in-single-lines/19882/3 "2022-07-14T11:58:05Z")

</div>

That was it! Thx!

Here’s the new code:

```auto
t# Parameter prompting for Azure subscription
PARAM(
    [string] [Parameter(Mandatory = $True, HelpMessage = "Choose subscription you want be inventoried")] $SubscriptionName
    )

#Login to Azure
Connect-AzAccount
 
#Select Azure Subscription
Get-AzSubscription -SubscriptionName $SubscriptionName | Select-AzSubscription

$rg = Get-AzResourceGroup | ?{ $_.ProvisioningState -eq "succeeded" } | select -expandproperty resourcegroupname
$results = 
foreach ($resourcegroup in $rg)
{
    $azResourceGroup = Get-AzResource -ResourceGroupName $resourcegroup | ? {$_.Type -match "Microsoft.Sql"}
    foreach ($azResource in $azResourceGroup) 
    {
    [PSCustomObject]@{
                     #Subscription = $SubscriptionName
                     ResourceGroup = $azResource.ResourceGroupName
                     ResourceName = $azResource.Name
                     ResourceType = $azResource.ResourceType
                     #Location = $azResource.Location
                     }
    }
}

# Return the results in table format
$results | ft

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [July 14, 2022, 12:05pm UTC](https://forums.powershell.org/t/format-output-in-single-lines/19882/4 "2022-07-14T12:05:59Z")

</div>

> [@anelliaf](#):
>
> That was it! Thx!

Great. I’m glad to hear that it helped. 🙂

> [@anelliaf](#):
>
> Here’s the new code:

Thanks for sharing. 👍🏽 🤟🏽

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:17pm UTC](https://forums.powershell.org/t/format-output-in-single-lines/19882/5 "2024-05-16T20:17:43Z")

</div>


