Hello!
I'm very new to Powershell, but committed to learning this! I've got a pretty simple script that works, but I'd like to pull one more bit of data out of the script and I'm having trouble understand how, but most importantly the concept behind how.
This is using Azure Powershell Module.
The script loops through all available azure subscriptions assigned to me, for each loop iteration it compares the SDK version of each deployment within the subscription to see if it's less (older) than version 2.2.0.0. and displays details on those
that match the -lt criteria. So far so good.
The problem is, I'd like to also add the SubscriptionName in the output for each loop iteration, making it possible to see which SubscriptionName matches with the deployment data that's displayed on screen.
Here's the script working without displaying SubscriptionName:
$subscriptionsArray = @()
Get-AzureSubscription |
foreach{
Select-AzureSubscription $_.SubscriptionName
$subscriptionsArray += (
Get-AzureService |
Get-AzureDeployment |
Where-Object -Property SDKVersion -lt "2.2.0.0" |
select ServiceName, SDKVersion, DeploymentID, DeploymentName | Format-table -AutoSize
)
}
write $subscriptionsArray
What I've tried doing (and am having a hard time understand the concept behind 'why' it's not working), is adding this to the array within the loop: Get-AzureSubscription -Current
$subscriptionsArray = @()
Get-AzureSubscription |
foreach{
Select-AzureSubscription $_.SubscriptionName
$subscriptionsArray += (
Get-AzureSubscription -Current
Get-AzureService |
Get-AzureDeployment |
Where-Object -Property SDKVersion -lt "2.2.0.0" |
select ServiceName, SDKVersion, DeploymentID, DeploymentName | Format-table -AutoSize
)
}
write $subscriptionsArray
But the piping within the array loop obviously will cause some errors. I would like help understanding how to add additional statements within the array loop without it affected the piped data. Is there any way to add additional statements within
that array loop? Why/Why not?
In the meantime, I created my own object, which seems to work, just not as clean output as I'd like (I'm like clean formatting!).
#$subscriptionsArray = @()
$sdkObject = New-Object System.Object
Get-AzureSubscription |
foreach{
Select-AzureSubscription $_.SubscriptionName
#$subscriptionsArray += (
$sdkObject | Add-Member -type NoteProperty -name SubscriptionName -Value $_.SubscriptionName -force
$sdkObject
Get-AzureService |
Get-AzureDeployment |
Where-Object -Property SDKVersion -lt "2.2.0.0" |
select ServiceName, SDKVersion, DeploymentID, DeploymentName | Format-table -AutoSize
#)
}
#write $subscriptionsArray
Thank you!