Powershell select statement

Clash Royale CLAN TAG#URR8PPPPowershell select statement
forEach($subscription in Get-AzureRmSubscription) {
Select-AzureRmSubscription -SubscriptionId $subscription.Id | Out-Null
Get-AzurermVM -Status | select $subscription.Name, ResourceGroupName, Name,
PowerState | ConvertTo-Csv -NoTypeInformation -Delimiter "|"}
I'm trying to return the results of this query, but it does not include the subscription name in the results. It shows it in the table header, but not in each line of the results. It should show it on every line, but it is blank for the first column on each row. I'm guessing this has to do with the subscription variable not being apart of the -Status properties, but it shows it in the table header?
1 Answer
1
If you want to include a static value as a property of the custom objects output by theSelect-Object cmdlet (select is a built-in alias name), you must use a calculated property:
Select-Object
select
... | Select-Object @{ n='SubscriptionName'; e={ $subscription.Name } },
ResourceGroupName,
Name,
PowerState | ...
By contrast, using $subscription.Name by itself is interpreted as the name of a property to access on each input object received.
$subscription.Name
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
@Alex: My pleasure; glad to hear it was helpful.
– mklement0
24 secs ago