Hi,
I have a script that creates an OU, several child OUs, a GPO for the parent OU and attempts to link the created GPO to the parent OU and pre-existing GPOs to the child OUs. I have everything working except the linking part works only some of the times and
it has me baffled as to why it's behaving this way. Sometimes the linking of the GPO for the parent OU would fail but the others work.
Here is the code snippet for the GPO linking:
if (!$noNewGPO) {
Write-Verbose "Creating the Unit Business Process GPO"
$BPGpo = New-GPO -Name "$Unit-$BusinessProcessName"
Write-Verbose "Setting permissions on the Unit Business Process GPO"
Set-GPPermissions -Name $BPGpo.DisplayName -PermissionLevel GpoEditDeleteModifySecurity -TargetName "IT-CMD-ClientAdmins" -TargetType Group
if (!$CentrallyManaged)
{
Set-GPPermissions -Name $BPGpo.DisplayName -PermissionLevel GpoEditDeleteModifySecurity -TargetName $OUAdminsGroup.Name -TargetType Group
}
Write-Verbose "Linking the Unit Business Process GPO"
New-GPLink -Name $BPGpo.DisplayName -Target $BPOU.DistinguishedName | Out-Null
}
if ($BaselineName) {
Write-Verbose "Linking the Unit Baseline GPO"
New-GPLink -Name "$BaselineName" -Target $BPOU.DistinguishedName | Out-Null
}
Write-Verbose "Linking the security policies"
New-GPLink -Name "SecurityPolicy-Low" -Target $LowOU.DistinguishedName | Out-Null
New-GPLink -Name "SecurityPolicy-Medium" -Target $MediumOU.DistinguishedName | Out-Null
New-GPLink -Name "SecurityPolicy-High" -Target $HighOU.DistinguishedName | Out-Null
New-GPLink -Name "SecurityPolicy-Shared" -Target $SharedOU.DistinguishedName | Out-NullAnd this is the error that pops up when it doesn't work:
powershell.exe : New-GPLink : There is no such object on the server.
At line:1 char:1
+ powershell.exe -executionPolicy Bypass -file "New-AUBusinessProcess-Rev1.ps1" -U ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (New-GPLink : Th... on the server.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
At C:\Users\user\Desktop\New-AUBusinessProcess-Rev1.ps1:120 char:2
+ New-GPLink -Name $BPGpo.DisplayName -Target $BPOU.DistinguishedName |
Out-Null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-GPLink], DirectoryService
sCOMException
+ FullyQualifiedErrorId : System.DirectoryServices.DirectoryServicesCOMExc
eption,Microsoft.GroupPolicy.Commands.NewGPLinkCommand
New-GPLink : There is no such object on the server.
At C:\Users\user\Desktop\New-AUBusinessProcess-Rev1.ps1:129 char:2
+ New-GPLink -Name "$BaselineName" -Target $BPOU.DistinguishedName |
Out-Null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-GPLink], DirectoryService
sCOMException
+ FullyQualifiedErrorId : System.DirectoryServices.DirectoryServicesCOMExc
eption,Microsoft.GroupPolicy.Commands.NewGPLinkCommand
Thanks for any help!