Description
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.
- ID: c93a37fb-a7f2-025a-90d6-a48e1bf1e6b1
- Version Independent ID: e23abbeb-19ae-469f-a24f-7ae35e26d229
- Content: Restore-GPO (GroupPolicy)
- Content Source: docset/winserver2022-ps/grouppolicy/Restore-GPO.md
- Product: w10
- GitHub Login: @JasonGerend
- Microsoft Alias: jgerend