Linking GPO to cross domain not working with powershell script

jay k 21 Reputation points
2021-04-09T07:40:30.64+00:00

Hello, need help to link the GPO to the cross domain, experiencing issue using the below script to link the GPO to cross domain.

cls
$gponame="testgpo"
$oulist= Get-Content -Path "c:\oulist.csv"
foreach ($ou in $oulist) {New-GPLink -Name $gponame -Domain abc.com -Server "D01.abc.com" -Target $ou}

Error : handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))
link.ps1:4 char:27

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,638 questions
{count} votes

Accepted answer
  1. Daisy Zhou 17,991 Reputation points Microsoft Vendor
    2021-04-12T03:47:31.877+00:00

    Hello anonymous user-0083,

    Thank you for posting here.

    What does your csv file look like?

    Does it look like this?

    Sample 1(there is head, there is the first line):

    86696-ou1.png

    Or does it look like this?

    Sample 2 (no head, no the first line):
    86647-ou2.png

    If it looks like sample 1(there is head, there is the first line), run command below:

    $gponame="test1"  
    $oulist= Import-Csv -Path "c:\oulist1.csv"   
    foreach ($OU in $oulist) {  
    New-GPLink -Name $gponame -Domain bb.b.local -Server "dfs1.bb.b.local" -Target $OU.OU  
    }  
    

    86683-ou3.png

    If it looks like sample 2 (no head, no the first line), run command below:

    $gponame="test1"  
    $oulist= Import-Csv -Path "c:\oulist1.csv" -Header ABC  
    foreach ($OU in $oulist) {  
    New-GPLink -Name $gponame -Domain bb.b.local -Server "dfs1.bb.b.local" -Target $OU.ABC  
    }  
    

    The result is as below:
    86721-result.png

    Tip:
    1-Please use Import-Csv instead of Get-Content.
    2-test1 is the gpo name in my child domain.
    3-LAPS1 is the OU in my parent domain.
    4-I have the same error as you in my lab if I use Get-Content.
    86712-the-same.png

    Best Regards,
    Daisy Zhou

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. jay k 21 Reputation points
    2021-04-14T10:56:24.047+00:00

    Hello DaisyZhou-MSFT,

    Input file looks like first sample, your 1st recommendation worked, Thank you for your help.

    Jay