{"id":54413,"date":"2009-02-11T21:09:00","date_gmt":"2009-02-11T21:09:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/02\/11\/hey-scripting-guy-how-can-i-create-new-group-policy-objects\/"},"modified":"2009-02-11T21:09:00","modified_gmt":"2009-02-11T21:09:00","slug":"hey-scripting-guy-how-can-i-create-new-group-policy-objects","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-create-new-group-policy-objects\/","title":{"rendered":"Hey, Scripting Guy! How Can I Create New Group Policy Objects?"},"content":{"rendered":"<h2><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> <\/h2>\n<p>Hey, Scripting Guy! Good morning. We are in the process of modifying our Group Policy implementation, and I anticipate having to create 15 or so new Group Policy objects. I know that I can open the Group Policy Management Console, right-click, and go through the wizard, but I would prefer to have a script that would create the Group Policy objects for me. Can this be done?<\/p>\n<p>&#8211; CC<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><\/p>\n<p>Hi CC,<\/p>\n<p>The good news is that we can do exactly what you asked. We can create new Group Policy objects from a script. The bad news is that we cannot do what you probably wanted to do, and that is to create a Group Policy object that does anything. There are third-party tools that will allow you to both create and configure Group Policy objects via script. In Windows 2008 R2, there are some pretty cool Group Policy cmdlets that provide additional capabilities. Without access to either of those solutions, you can create a Group Policy object via script and configure it later\u2014so it helps.<\/p>\n<table id=\"EXC\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">This week is Group Policy week. We will spend the week looking at some of the things you can do using Windows PowerShell when you have access to the COM object that ships with the Group Policy Management Console. There are some good VBScripts that illustrate working with Group Policy in the <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/scripts\/default.mspx?mfr=true\">Script Center Script Repository<\/a>, and in the <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/csc\/scripts\/policy\/default.mspx\">Community-Submitted Scripts Center<\/a>. You can also download a collection of <a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyID=38c1a89b-a6d2-4f2a-a944-9236999aee65&amp;DisplayLang=en\">sample Group Policy management scripts<\/a>.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>The script that will create a GPO is called, surprisingly enough, <b>CreateGPO.ps1<\/b>.<\/p>\n<p><b>CreateGPO.ps1<\/b><\/p>\n<pre class=\"codeSample\">param(\n      $domain = $env:userDNSdomain,\n      $gpoName = ($paramMissing=$true),\n      [switch]$whatif,\n      [switch]$help,\n      [switch]$examples,\n      [switch]$min,\n      [switch]$full\n      ) #end param\n# Begin Functions\nfunction Get-HelpTopic()\n{\n $descriptionText= `\n@\"\n NAME: CreateGPO.ps1\n DESCRIPTION:\n Creates a new GPO in a specified Domain by\n using default settings. This GPO can then\n easily be modified by using the GPMC\n This script supports prototyping by using\n the -whatif switch.\n PARAMETERS:\n -Domain domain to create the new GPO\n -gpoName name of the GPO to create\n -whatif prototypes the command\n -help prints help description and parameters file\n -examples prints only help examples of syntax\n -full prints complete help information\n -min prints minimal help. Modifies -help\n\"@ #end descriptionText\n$examplesText= `\n@\"\n SYNTAX:\n CreateGPO.ps1\n Displays an error missing parameter, and calls help\n CreateGPO.ps1  -gpoName \"SetScreenSaverTimeout\"\n Creates a GPO named SetScreenSaverTimeout in the local\n domain using the default GPO settings\n CreateGPO.ps1 -gpoName \"SetScreenSaverTimeout\" -domain \"nwtraders.com\n Creates a GPO named SetScreenSaverTimeout in the nwtraders.com domain\n CreateGPO.ps1 -gpoName \"SetScreenSaverTimeout\" -domain \"nwtraders.com -whatif\n Displays what if: Perform operation create GPO SetScreenSaverTimeout in\n domain nwtraders.com\n CreateGPO.ps1 -help\n Prints the help topic for the script\n CreateGPO.ps1 -help -full\n Prints full help topic for the script\n CreateGPO.ps1 -help -examples\n Prints only the examples for the script\n CreateGPO.ps1 -examples\n Prints only the examples for the script\n\"@ #end examplesText\n$remarks = `\n\"\nREMARKS\n     For more information, type: $($MyInvocation.ScriptName) -help -full\n\" #end remarks\n  if($examples) { $examplesText ; $remarks ; exit }\n  if($full)     { $descriptionText; $examplesText ; exit }\n  if($min)      { $descriptionText ; exit }\n  $descriptionText; $remarks\n  exit\n} #end Get-HelpTopic function\nfunction New-Line (\n                  $strIN,\n                  $char = \"=\",\n                  $sColor = \"Yellow\",\n                  $uColor = \"darkYellow\",\n                  [switch]$help\n                 )\n{\n if($help)\n  {\n    $local:helpText = `\n@\"\n     New-Line accepts inputs: -strIN for input string and -char for seperator\n     -sColor for the string color, and -uColor for the underline color. Only\n     the -strIn is required. The others have the following default values:\n     -char: =, -sColor: Yellow, -uColor: darkYellow\n     Example:\n     New-Line -strIN \"Hello world\"\n     New-Line -strIn \"Morgen welt\" -char \"-\" -sColor \"blue\" -uColor \"yellow\"\n     New-Line -help\n\"@\n   $local:helpText\n   break\n  } #end New-Line help\n $strLine= $char * $strIn.length\n Write-Host -ForegroundColor $sColor $strIN\n Write-Host -ForegroundColor $uColor $strLine\n} #end New-Line function\nFunction Get-Whatif()\n{\n \"what if: Perform operation create GPO $gpoName in domain $domain\"\n exit\n} #end Get-Whatif\nFunction New-GPO()\n{\n$error.clear()\n $gpm = new-object -comobject GPMgmt.gpm\n $constants = $gpm.getConstants()\n $gpmDomain = $gpm.getDomain($domain,$null, $constants.UseAnyDC)\n $gpmGPO = $gpmDomain.CreateGPO()\n $gpmGPO.DisplayName = $gpoName\n if($error.count -ne 0)\n   {\n    $GPMGPO.Delete()\n    New-Line -strIN \"An error occurred creating $gpoName\" -scolor red\n    \"The error was $($error.categoryInfo)\"\n  }\n else\n  {\n   Write-host \"Created GPO $($gpmGPO.displayname)\"\n  }\n} #end New-GPO\n# Entry Point\nif($help)      { Get-HelpTopic }\nif($examples)  { Get-HelpTopic }\nif($full)      { Get-HelpTopic }\nif($whatif)    { Get-Whatif }\nif($paramMissing) { \"GPO name is required\" ; Get-HelpTopic }\nif($gpoName) { New-GPO }\n&nbsp;<\/pre>\n<p>The <b>CreateGPO.ps1<\/b> is written in the same style as the other GPO scripts we have seen this week. Please refer to the articles from <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/feb09\/hey0209.mspx\" target=\"_blank\">Monday<\/a> and <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/feb09\/hey0210.mspx\" target=\"_blank\">Tuesday<\/a> to see information about the command-line parameters and the help function.<\/p>\n<p>After we get past the command-line parameters and the help function, the next function to talk about is the <b>Get-Whatif<\/b> function, which tells us what the script will do after you have configured the parameters. An example of running the script with <b>whatif<\/b> is seen here:<\/p>\n<pre class=\"codeSample\">CreateGPO.ps1 -gpoName \"SetScreenSaverTimeout\" -domain \"nwtraders.com \u2013whatif<\/pre>\n<p>When the above command is typed, it displays <b>what if: Perform operation create GPO SetScreenSaverTimeout in domain nwtraders.com<\/b>. This is useful not only because it will give you confidence about what the command will actually do, but also because it will give troubleshooting help. This is because it lets you know which values have been received for which parameters. The <b>Get-Whatif<\/b> function basically prints out a string and the values that are supplied to the <b>$gpoName<\/b> variable and the <b>$domain<\/b> variable. Both of these variables obtain their value from the command line when the script is launched; however,. by default the <b>$domain<\/b> variable is obtained by reading the environmental variable <b>userDNSDomain<\/b> off the environmental drive. The <b>Get-Whatif<\/b> function is seen&nbsp; here:<\/p>\n<pre class=\"codeSample\">Function Get-Whatif()\n{\n \"what if: Perform operation create GPO $gpoName in domain $domain\"\n exit\n} #end Get-Whatif\n<\/pre>\n<p>The main portion of the script is the <b>New-GPO<\/b> function. The first thing we do is create an instance of the <b>GPMgmt.gpm<\/b> object. We can use this object if the Group Policy Management Console is installed. For Windows Vista with SP1, you will need to <a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyID=9ff6e897-23ce-4a36-b7fc-d52065de9960&amp;DisplayLang=en\" target=\"_blank\">install RSAT<\/a>. Here is the line of code that creates the <b>GPMgmt.gpm<\/b> object:<\/p>\n<pre class=\"codeSample\">$gpm = new-object -comobject GPMgmt.gpm<\/pre>\n<p>The next thing we need to do is to use the <b>GetConstants<\/b> method, which returns the constants and their associated values to use with the <b>GPMgmt.gpm<\/b> object. All the constants and their values are seen in Table 1.<\/p>\n<table id=\"E2F\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead>\n<tr>\n<td class=\"tableHeader\" colSpan=\"2\">Table 1 Group Policy Management API constant values<\/td>\n<\/tr>\n<tr class=\"stdHeader\" vAlign=\"top\">\n<td id=\"colE5F\">Constant<\/td>\n<td id=\"colECG\">Value<\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permGPOApply<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">65536<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permGPORead<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">65792<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permGPOEdit<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">65793<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permGPOEditSecurityAndDelete<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">65794<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permGPOCustom<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">65794<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permWMIFilterEdit<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">131072<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permWMIFilterFullControl<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">131073<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permWMIFilterCustom<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">131074<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permSOMLink<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1835008<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permSOMLogging<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1573120<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permSOMPlanning<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1573376<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permSOMGPOCreate<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1049600<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permSOMWMICreate<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1049344<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permSOMWMIFullControl<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1049345<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyGPOPermissions<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyGPOEffectivePermissions<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyGPODisplayName<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyGPOWMIFilter<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">3<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyGPOID<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">4<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyGPOComputerExtensions<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">5<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyGPOUserExtensions<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">6<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertySOMLinks<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">7<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyGPODomain<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">8<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyBackupMostRecent<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">9<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchOpEquals<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchOpContains<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchOpNotContains<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchOpNotEquals<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">3<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">UsePDC<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">UseAnyDC<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">DoNotUseW2KDC<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">somSite<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">somDomain<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">somOU<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">DoNotValidateDC<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">ReportHTML<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">ReportXML<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">RSOPModeUnknown<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">RSOPModePlanning<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">RSOPModeLogging<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">EntryTypeUser<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">EntryTypeComputer<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">EntryTypeLocalGroup<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">EntryTypeGlobalGroup<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">3<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">EntryTypeUniversalGroup<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">4<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">EntryTypeUNCPath<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">5<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">EntryTypeUnknown<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">6<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">DestinationOptionSameAsSource<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">DestinationOptionNone<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">DestinationOptionByRelativeName<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">DestinationOptionSet<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">3<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">MigrationTableOnly<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">ProcessSecurity<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">RsopLoggingNoComputer<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">65536<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">RsopLoggingNoUser<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">131072<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">RsopPlanningAssumeSlowLink<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">RsopPlanningAssumeUserWQLFilterTrue<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">8<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">RsopPlanningAssumeCompWQLFilterTrue<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">16<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">BackupTypeGPO<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">BackupTypeStarterGPO<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">StarterGPOTypeSystem<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">StarterGPOTypeCustom<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyStarterGPOPermissions<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">10<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyStarterGPOEffectivePermissions<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">11<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyStarterGPODisplayName<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">12<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyStarterGPOID<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">13<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">SearchPropertyStarterGPODomain<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">14<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permStarterGPORead<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">197888<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permStarterGPOEdit<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">197889<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permStarterGPOFullControl<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">197890<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">permStarterGPOCustom<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">197891<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">ReportLegacy<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">ReportComments<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>After we have created the constants and stored them in a variable, we can use them directly when we obtain a connection to the domain. This is seen&nbsp;here:<\/p>\n<pre class=\"codeSample\">$constants = $gpm.getConstants()\n $gpmDomain = $gpm.getDomain($domain,$null, $constants.UseAnyDC)\n<\/pre>\n<p>After we have connected to the domain, we use the <b>CreateGPO<\/b> method to create a Group Policy object. And after we have created the GPO, we need to specify the display name for it:<\/p>\n<pre class=\"codeSample\">$gpmGPO = $gpmDomain.CreateGPO()\n $gpmGPO.DisplayName = $gpoName\n<\/pre>\n<p>Because we are creating a new GPO, we might be interested in seeing if it was actually created. To do this, we check the error count. If the error count is not equal to 0, a problem occurred and we delete the GPO. Otherwise, the operation was successful and everything is groovy. This is seen&nbsp;here:<\/p>\n<pre class=\"codeSample\">if($error.count -ne 0)\n   {\n    $GPMGPO.Delete()\n    New-Line -strIN \"An error occurred creating $gpoName\" -scolor red\n    \"The error was $($error.categoryInfo)\"\n  }\n else\n  {\n   Write-host \"Created GPO $($gpmGPO.displayname)\"\n  }\n} #end New-GPO\n<\/pre>\n<p>Well, CC, that is the good news when it comes to creating GPOs: you can do it via scripting. Hope this helps, and that it saves you some time and effort in your new Group Policy plan. Join us tomorrow when we will talk about finding GPOs that have no security filtering applied. See you then.<\/p>\n<p>&nbsp;<\/p>\n<p><b>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Good morning. We are in the process of modifying our Group Policy implementation, and I anticipate having to create 15 or so new Group Policy objects. I know that I can open the Group Policy Management Console, right-click, and go through the wizard, but I would prefer to have a script that [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[152,3,45],"class_list":["post-54413","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-group-policy","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Good morning. We are in the process of modifying our Group Policy implementation, and I anticipate having to create 15 or so new Group Policy objects. I know that I can open the Group Policy Management Console, right-click, and go through the wizard, but I would prefer to have a script that [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/54413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=54413"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/54413\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=54413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=54413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=54413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}