Backup GPO by displayname and not ID – powershell

Question:

I want to backup GPOs using their names instead of their ID’s. Currently I have:

I can post any other parts of the script as needed but most of the missing variable values shouldn’t matter for the question. As of now, it still backs up the GPO’s as their ID’s

Answer:

So I decided to change the code a bit so I could debug what was going on. I added writeout $GPOBackup and writeout $GPO. Interestingly this is similar to what I saw. (Example taken from Microsoft page)

writeout $GPOBackup provided me with:


writeout $GPO provided me with:

As you can see in the first output there is a GpoId and an Id. The output of the second command suddenly changes the Id to what was originally the GpoID. When the backup-gpo command saves the GPO it saves it using the Id that you receive from the first block of code. The Id then changes to what is the GpoId. I have no clue as to why this happens but at any rate, the fix for me was simple once I figured this out. The follow code allowed me to backup GPOs as DisplayName

Source:

Backup GPO by displayname and not ID – powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply