Share via


How to add comment for a GPO with PowerShell

You might have seen GP MVP Jeremy Moskowitz’s post on how to recycle GPO comments. While Jeremy points out you can do this without a script…. You can also do it with a script! Our tech writer, Judith, walks us through the process:

 

After I import the Group Policy module in PowerShell, I have access to the Get-GPO cmdlet. If I run that to create an object representing my test GPO:

 PS C:\ > $testGPO = Get-GPO testGPO

PS C:\ > $testGPO

DisplayName : testGPO

DomainName : corp.contoso.com

Owner : CORP3\Domain Admins

Id : 4364e8c5-23a0-4020-9624-4dbcaac9c8c2

GpoStatus : AllSettingsEnabled

Description :

CreationTime : 5/9/2011 10:07:09 AM

ModificationTime : 6/27/2011 3:51:20 PM

UserVersion : AD Version: 1, SysVol Version: 1

ComputerVersion : AD Version: 1, SysVol Version: 1

WmiFilter :

 

 

I was pretty sure that Description would show the comment for the GPO. And I ran the Get-Member cmdlet against the $testGPO object just to verify that I can use the Description property to set the comment using PowerShell.

 

 PS C:\ > $testGPO | gm -Membertype property

    TypeName: Microsoft.GroupPolicy.Gpo

    Name MemberType Definition

    ---- ---------- ----------

    Computer Property Microsoft.GroupPolicy.ComputerConfiguration Computer {get;}

    CreationTime Property System.DateTime CreationTime {get;}

    Description Property System.String Description {get;set;}

    DisplayName Property System.String DisplayName {get;set;}

    DomainName Property System.String DomainName {get;}

    GpoStatus Property Microsoft.GroupPolicy.GpoStatus GpoStatus {get;set;}

    Id Property System.Guid Id {get;}

    ModificationTime Property System.DateTime ModificationTime {get;}

    Owner Property System.String Owner {get;}

    Path Property System.String Path {get;}

    User Property Microsoft.GroupPolicy.UserConfiguration User {get;}

    WmiFilter Property Microsoft.GroupPolicy.WmiFilter WmiFilter {get;set;}

Then I changed the comment by setting $testGPO.Description to a string value, which just looks like a simple assignment:

 PS C:\ > $testGPO.description="This is my test GPO. I'm using this to try out GP and PowerShell."

PS C:\ > $testGPO

    DisplayName : testGPO

    DomainName : corp.contoso.com

    Owner : CORP3\Domain Admins

    Id : 4364e8c5-23a0-4020-9624-4dbcaac9c8c2

    GpoStatus : AllSettingsEnabled

    Description : This is my test GPO. I'm using this to try out GP and PowerShell.

    CreationTime : 5/9/2011 10:07:09 AM

    ModificationTime : 6/27/2011 3:51:20 PM

    UserVersion : AD Version: 1, SysVol Version: 1

    ComputerVersion : AD Version: 1, SysVol Version: 1

    WmiFilter :

Here’s the GPMC snapshot before changing the comment:

clip_image002

And here’s the GPMC snapshot after I changed the comment:

clip_image004

Comments

  • Anonymous
    September 09, 2014
    How to add comment for a GPO with PowerShell - Group Policy Team Blog - Site Home - TechNet Blogs
  • Anonymous
    October 22, 2014
    How to add comment for a GPO with PowerShell - Group Policy Team Blog - Site Home - TechNet Blogs