Powershell select statement

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Powershell 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 the
Select-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





@Alex: My pleasure; glad to hear it was helpful.
– mklement0
24 secs ago






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.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived