Group policy powershell question

Alex
Alex used Ask the Experts™
on
Peeps,

Just need confirmation that this will work

Text file has the name of the GPO

$GPOs = Get-content c:\temp\gpotoremove.txt
Foreach($GP in $GPOs){Backup-gpo -name $GP -path "C:\GPObackup\$($GP\"}

and to delete

$GPOs = Get-content c:\temp\gpotoremove.txt
Foreach($GP in $GPOs){Remove-gpo -name $GP -confirm $False}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
The subexpression around the $GP variable in the backup path is missing the closing round bracket.
And you could basically backup all the GPOs into the same folder; the manifest.xml in the root folder will be updates when a new backup is added.

$GPOs = Get-Content c:\temp\gpotoremove.txt
ForEach ($GPO In $GPOs) {Backup-Gpo -Name $GPO -Path "C:\GPObackup\$($GPO)"}

Open in new window

Or use the pipeline:
Get-Content c:\temp\gpotoremove.txt | ForEach-Object {Backup-Gpo -Name $_ -Path "C:\GPObackup\$($_)"}

Open in new window

$GPOs = Get-Content c:\temp\gpotoremove.txt
ForEach ($GPO In $GPOs) {Remove-Gpo -Name $GPO -Confirm:$false}

Open in new window

Get-Content c:\temp\gpotoremove.txt | ForEach-Object {Remove-Gpo -Name $_ -Confirm:$false}

Open in new window

AlexSenior Infrastructure Analyst

Author

Commented:
Thanks buddy

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial