Unable to get group-object to correctly group based upon a noteProperty I created which is 3 different subscription tags from azure subscriptions. I wanna be able to combine them if the contact matches but so far I’ve only be able to group them based on if they have a contact property. I can share more code for better understanding if need be and I appreciate all the help anyone can provide. Pretty much pulling data from an app then signing into azure to get tag info, storing that info in variable then wanna be able to compare if they match then combine them.
Taylor White,
Welcome to the forum.
Please do. It would be great if you shared a minimal reproducable example. It does not have to be the original code with original data.
And it may help if you shared the expected result as well.
Please do not post images of code as this does not help at all. Instead post the plain text formatted as code.
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thanks in advance
Guide to Posting Code - Redux <---- Click
( !! Sometimes the preformatted text button hides behind the settings gear symbol. )
And again … since we do not have access to your data you should post a minimal REPRODUCABLE expample with sample data!!!
You can edit your existing post - you don’t need to create a new reply.
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thanks in advance
Guide to Posting Code - Redux <---- Click
( !! Sometimes the preformatted text button hides behind the settings gear symbol. )
Please do not create a new post - edit your existing one!
$tenantId = "Value"
$clientId = "Value"
$clientSecret = "Value"
$authBody = @{
grant_type = "client_credentials"
client_id = $clientId
client_secret = $clientSecret
scope = "https://management.azure.com/.default"
}
$authResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantID/oauth2/v2.0/token" -Method Post -Body $authBody
$accessToken = $authResponse.access_token
$headersGraph = @{
Authorization = "Bearer $accessToken"
ContentType = "application/json"
}
# Loop through each account ID and query Azure subscription details
$alert_data | Group-Object -Property "Account" | ForEach-Object {
$acc_id = $_.Group[0].AccountID
$graphUri = "https://management.azure.com/subscriptions/$($acc_id)?api-version=2021-01-01"
# Call Azure Management API to get subscription details
Try{
$subscriptionResponse = Invoke-RestMethod -Method Get -Uri $graphUri -Headers $headersGraph -ErrorAction Stop
#Map the data for this subscription
$acc_id_emails = @($subscriptionResponse.tags.owner,$subscriptionResponse.tags.technical_contact, $subscriptionResponse.tags.svp) | Where-Object { $_ -ne $null -and $_ -ne ""}
$_.Group | ForEach-Object {$_ | Add-Member -MemberType NoteProperty -Name "Contact" -Value $acc_id_emails}
}#close try
catch{
Write-Output "No subscription response for Account ID: $accountId"
$_.Group | ForEach-Object {$_ | Add-Member -MemberType NoteProperty -Name "Contact" -Value $null}
}#close catch
}#close foreach
$error_array = @()
# Validate and process mapped data
$alert_data | Group-Object -Property "Contact" | ForEach-Object {
$alert_group = $_.Group
if(![String]::IsNullOrEmpty($alert_group[0].Contact)){
Do you actually read my replies?
Since I do not have access to your data and I do not have access to an Azure tenant to maybe recreate your issue you will have to provide us with a minimal reproducable example.
That means you should create some sample data looking similar to the data you’re working with. Then you provide the code you try to manipulate this sample data with. And then you show how the expected output should look like.
Please put a little effort in it and please do not create a new reply or at least delete your old useless ones.
Thanks in advance.
And BTW: in the code you shared you are using the variable $alert_data
but you never define or fill in this variable!!