Okta API & Powershell

I am trying to create a routing to mirror our prod and prev environments.

I am having an issue with the -match function in powershell not working correctly.

I have the preview groups in an array called $PrevGroupInfo but when I try to search for the name of the prod group it doesn’t match anything. If I to the .profile.name search, it will return the name, but not the rest of the info.

Any help would be greatly appreciated!

Clear-host

$ProdSite = “https://logrhythm.okta.com

$PrevSite = “https://logrhythm.oktapreview.com

import-module OktaAPI

Connect-Okta $ProdToken $ProdSite

#Get Prod Users & Groups
$ProdGroupInfo = Invoke-Method GET “/api/v1/groups?limit=10000”
$ProdUserInfo = Invoke-Method GET “/api/v1/users?limit=10000”

Connect-Okta $PrevToken $PrevSite

#Get Prev Users & Groups
$PrevGroupInfo = Invoke-Method GET “/api/v1/groups?limit=10000”
$PrevUserInfo = Invoke-Method GET “/api/v1/users?limit=10000”

ForEach ($Group in $ProdGroupInfo)
{
If ($Group.count -gt 0)
{
Connect-Okta $ProdToken $ProdSite

        #Get Group Members from Prod
        $Members = Get-OktaGroupMember $Group.id
        $GroupName = $Group.profile.name

        Connect-Okta $PrevToken $PrevSite
        $NewGroup = @()

        #***** Get Preview Group Name & ID
        If ($PrevGroup = $PrevgroupInfo -match $Group.profile.name)
        {
            $NewGroup += $PrevGroup
            Write-Host "Preview Group: " $NewGroup `t`t "ID: " $NewGroup.id -ForegroundColor DarkGreen
        }
        else 
        {
            Write-Host "Group not matched in Preview: " $Group.profile.name -ForegroundColor Red
        }

<#> If ($Members -ne $null)
{
ForEach ($Item in $Members)
{
Write-Host tt "Item: " $Item.profile.displayname tt "ID: " $Item.id
}
Pause
}#>
}
}