Skip to content

Restore-GPO with -BackupId parameter recreates missing GPO but documentation says that should fail #3656

Open
@skawood

Description

@skawood

The Description section of the Restore-GPO documentation says, "if the GPO no longer exists in the domain, the cmdlet fails." I find that's true if I identify the GPO with the -Name or -Guid parameters. But using the -BackupId parameter works, it recreates a missing GPO. Is this intended and reliable functionality that I can depend on?

I observed this on a Windows Server 2019 domain controller in a Windows Server 2016 domain. The domain only has one DC and the commands were run locally on the DC so I don't think I'm getting a false result due to replication delays or other factors. This is with PowerShell 5.1 and version 1.0.0.0 of the GroupPolicy PowerShell module. To reproduce, either run Restore-GPO with the -BackupId parameter or pass a GpoBackup object to Restore-GPO through the pipeline, for example, given a GPO "Test GPO":

$Backup = Backup-GPO -Name "Test GPO" -Path <backup path>
Remove-GPO -Name "Test GPO"
# Calling Restore-GPO with -Name parameter gives "GPO was not found" exception, consistent with documentation.
Restore-GPO -Name "Test GPO" -Path <backup path>
# Also GPO not found using -Guid parameter, consistent with documentation
Restore-GPO -Guid "<GPO Guid>" -Path <backup path>
# This works, using -BackupId parameter, contrary to documentation, and this also works with the string literal of the backup Id.
Restore-GPO -BackupId $Backup.Id -Path <backup path>
# This works too
$Backup | Restore-GPO

The above works with and without removing the GPO, but my question is in the case of removing the GPO, Restore-GPO works when the documentation says it would fail, but only with the -BackupId parameter. Thank you very much. 


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Labels

area-grouppolicyIssues for grouppolicy moduledoc-bugFor Upwork freelance team categories/reporting.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions