Need to automate the creation of GPO's in a PowerShell script

I have the need to create an OU, Group, and GPO for every user on our domain. (too complicated to go into)  I have created a PowerShell script that reads through a text file for new handles and creates the OU and groups and even assigns the default members for the group.  That is 2 out of 3 anyway.  I am having trouble making a GPO and linking it to the OU.  Anyone good with PowerShell?  I am enclosing my script. -It works except for the GPO part that I have left a space for...

thanks for the help

# This script creates an OU in: Company Users OU based on a user's Handle.
# It then creates an access group inside the OU based on that same handle and adds default members to that group
# All handles are read from a text file listed below

# Call the text file to read the handles from
$TextFile = GC -Path "C:\Temp\New.Txt"
ForEach ($objItem in $TextFile){

# Set The OU Name to the line read from the txt file
$OUName = $objItem
# Set the Group name by appending the previous varriable with "Access"
$GRPName = ($objItem + " Access")

#Set the GPO Name

# Set the UPN for the Domain
$Domain = ",dc=domain,dc=com"

# Set the UPN for the group that is to be created
$group = [ADSI](LDAP://cn=" + $GRPName + ",OU=" + $OUName + ",OU=Company Users" + $Domain)

# Set the members to be added to the group created
$Add1 = ("CN=Computer Admins,OU=Users" + $Domain)
$Add2 = ("CN=Domain Admins,OU=Users" + $Domain)
$Add3 = ("CN=GCS Admins,OU=Users" + $Domain)

# Create the OU
$objDomain2 = [ADSI]("LDAP://OU=Company Users" +$Domain)
$objOU = $objDomain2.Create("OrganizationalUnit", "OU= " + $OUName)

#     Here is where I need to create a GPO named $GPOName and link it to
#        ("OU=" + $OUName + ",OU=Company Users" + $Domain)

# Create the Group in the OU just added
$objDomain = [ADSI]("LDAP://OU=" + $OUName + ",OU=Company Users" + $Domain)
$objOU = $objDomain.Create("Group", "CN= " + $GRPName)

# Add members to the group just added

Who is Participating?
BSonPoshConnect With a Mentor Commented:
Oh... you do need the GPMC installed on the machine with the tools installed. The cmdlets use the COM interface provided by GPMC
check out the free cmdlets by They will let you create and link GPOs from Powershell.

The even have a pay tool that is absolutely amazing for actually setting GPO settings.

FYI: Powershell Zone:
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Denver_ITAuthor Commented:
Well I installed the software but it does not seem to work.  Do I have to have .net framework installed on the DC?
No need for framework.

Did you add the snapin?

Try this
get-pssnapin -reg | add-pssnapin -ea 0

Denver_ITAuthor Commented:
The get-pssnapin -reg | add-pssnapin -ea 0 seems to have done the trick.  It is now registered.  Thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.