Exchange administrative privileges

Im restructuring a legacy ad
Finished creating the script to create the tree itself with nessesary acl etc

What i want todo now is create appropriate exchange administrative role groups so that for everyou there are separate administrators
i can do it via gui but cannot via powershell


Import-Module ActiveDirectory
Add-PSSnapin microsoft.exchange.management.powershell.snapin
Add-PsSnapin Microsoft.Forefront.Filtering.Management.Powershell

$usersOu = "myOU"
$userGroups = Get-ADGroup -SearchBase $usersOu -Filter * -Properties Description

foreach ($userGroup in $userGroups) {
    $groupName = $userGroup.Name
    $groupName = $groupName -split "AD ROLE "
    $groupNameWeNeed = $groupName[1]
    $description = $userGroup.Description
    $descriptionSplitter = $description -split ": "
    $skoop = $descriptionSplitter[1].Trim()
    $ou = (Get-ADOrganizationalUnit $skoop).DistinguishedName
    $roleGroupName = "new_Recipient Management - $groupNameWeNeed"
    New-RoleGroup -Name $roleGroupName `
    -Roles "Active Directory Permissions","Mail Recipient Creation","Mail Recipients", -RecipientOrganizationalUnitScope $ou
    #-RecipientOrganizationalUnitScope
    #-CustomRecipientWriteScope

}

I keep getting error on the New-rolegroup creation like it couldnt find the ou
but it cant be the case cuz i define the variable $ou and its fine
i have granted myself fullaccess over the ad ou
exchange onpremise 2019
productversion: 15.02.1118.030

If i do the rolegroup via gui i can put in the ou like in picture where red has been used

Nimrod,
Welcome to the forum. :wave:t3:

It is very hard to distinguish between text and code. Please go back, edit your question once again and fix the formatting of your 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

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )