question

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

Hello, could you please help with the powershell script to link the GPO to multiple OUs with OUs inout file

Looking for powershell script to link the GPO to multiple OUs

windows-server-powershellwindows-group-policy
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.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered IanXue-MSFT commented

Hi,

The New-GPLink cmdlet links a GPO to an OU like below

  $OUs = "OU=ou1,DC=contoso,DC=com", "OU=ou2,DC=contoso,DC=com"
  $OUs | ForEach-Object {
     New-GPLink -Name "MyGPO" -Target $_
  }


Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 4
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.

Ian Xue Thank you. wanted to have a CSV as input file, which will have a list of OUs as there are are around more 400 OUs to which the GPO needs to link. could you please help with CSV file as input for OUs, and the link should be enabled.

0 Votes 0 ·

Assuming the header of the CSV file is "OU" you can import it like this

 $file = "C:\temp\OUlist.csv"
 Import-Csv -Path $file | ForEach-Object {
         New-GPLink -Name "MyGPO" -Target $_.OU
     }


0 Votes 0 ·

Ian Xue Thank you for your support.

0 Votes 0 ·
Show more comments