I am working in Azure and trying to loop through all Subscriptions tags in my tenant and return all results in a list with a specific tag name + value. The idea is to auto alert certain people when platform changes are happening or incidents occur (sort of cheap mans ITSM).
$SubTags.Properties.TagsProperty
$ArrayOfTags = @()
ForEach($s in $SubTags) {
if ($SubTags.Properties.TagsProperty -contains "Environment"){
$ArrayOfTags += $SubTags
}
else {
Write-Host "fail"
}
}
Return $ArrayOfTags
All i get is:
fail
fail
fail
fail
fail
fail
fail
....
I have tried with some dummy code
$aa = @("aa","bb","cc", "cc")
[System.Collections.ArrayList]$bbb = @()
ForEach ($a in $aa){
if ($aa -eq "cc") {
$bbb.Add($_)
Write-Host "cool cool cool"
}
else {
Write-Host ":("
}
}
Return $bbb
And i get:
0
cool cool cool
1
cool cool cool
2
cool cool cool
3
cool cool cool
Returned.
I appreciate that this might be a bit to vague, but I am new to ps, so appreciate any sort of help :-)
Good day