• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 718
  • Last Modified:

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

----------------------
START OF SCRIPT
----------------------
# 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
GPOName=$ObjItem

# 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)
$objOU.setInfo()

#
#
#     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)
$objOU.setInfo()

# Add members to the group just added
$group.Member.Add("$Add1")
$group.Member.Add("$Add2")
$group.Member.Add("$Add3")
$group.setInfo()

}
----------------------
END OF SCRIPT
----------------------
0
Denver_IT
Asked:
Denver_IT
  • 4
  • 2
1 Solution
 
BSonPoshCommented:
check out the free cmdlets by www.sdmsoftware.com. 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: http://www.experts-exchange.com/Programming/Languages/Scripting/MSH-Monad/
0
 
BSonPoshCommented:
0
 
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?
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
BSonPoshCommented:
No need for framework.

Did you add the snapin?

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

0
 
BSonPoshCommented:
Oh... you do need the GPMC installed on the machine with the tools installed. The cmdlets use the COM interface provided by GPMC
0
 
Denver_ITAuthor Commented:
The get-pssnapin -reg | add-pssnapin -ea 0 seems to have done the trick.  It is now registered.  Thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now