Need Help in Setting GPO on OU

Hello Everyone,

This is my first post need your help.

Actually i am trying to apply Gpo on OU but it is throwing exception when i am trying to run it from AZure Devops pipeline on the build server but working fine when running it directly on build server through powershell after rdp.

below are the code snippet:

foreach($Policy in $Policys){
try{
Write-Host "`nApplying GPO :$Policy on OU: $oU "
$t=Get-GPO -Name $Policy
New-GPLink -Name $Policy -Target $oU -Domain $domainName
}
catch{
Write-Host “Error Occured for GPO: $Policy - $_.Exception.Message”
}
}

exception occured:
Error Occured for GPO: server admin - Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).Exception.Message

your help is highly appreciated