question

jayk-0083 avatar image
0 Votes"
jayk-0083 asked DaisyZhou-MSFT commented

Linking GPO to cross domain not working with powershell script

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-group-policy
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello anonymous user-0083,

Would you please tell me how things are going on your side. If you have any questions or concerns about the information I provided, please don't hesitate to let us know.
Thanks for your time and have a nice day!

Best Regards,
Daisy Zhou


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

0 Votes 0 ·
DaisyZhou-MSFT avatar image
0 Votes"
DaisyZhou-MSFT answered DaisyZhou-MSFT edited

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.


ou1.png (4.8 KiB)
ou2.png (4.9 KiB)
ou3.png (31.0 KiB)
result.png (56.9 KiB)
the-same.png (90.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

jayk-0083 avatar image
0 Votes"
jayk-0083 answered DaisyZhou-MSFT commented

Hello DaisyZhou-MSFT,

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

Jay

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello anonymous user-0083,

Thank you for your update and accepting my reply as answer. I am very glad that the information is helpful and the problem has been solved.
As always, if there is any question in future, we warmly welcome you to post in this forum again. We are happy to assist you!

Best Regards,
Daisy Zhou

0 Votes 0 ·