Forum Discussion
Get-DistributionGroup error
I’d first check whether the problem is related to how the script is resolving the group rather than the group actually being missing. Since Get-DistributionGroup -Identity Group5 works manually, that suggests the object itself exists and Exchange Online can resolve it.
One thing I’d test is capturing the exact value being passed through $stringAlias and $stringName immediately before Get-DistributionGroup. Hidden whitespace, an unexpected value, or a difference between the alias and display name could cause the scripted lookup to behave differently.
I’d also test the lookup with an explicit result variable and $ErrorActionPreference = 'Stop' so the script isn't treating an error object from 2>&1 as a normal result. That can make $objectDistriGroup -eq $null behave unexpectedly because the command's error output may be captured in the variable.
For example, separating the lookup from error handling should make it easier to determine whether the failure is actually the Get-DistributionGroup lookup or the subsequent Add-DistributionGroupMember operation.