-
-
Save snovvcrash/ecdc639b061fe787617d8d92d8549801 to your computer and use it in GitHub Desktop.
Set the status of a Group Policy Object with Powershell (https://web.archive.org/web/20200918222531/https://powershell.org/2013/02/set-gpo-status-with-powershell/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Set-GPOStatus | |
{ | |
<# | |
.Synopsis | |
Set the status of a Group Policy Object | |
.Description | |
Sets the status of one or more Group Policy objects. | |
.Example | |
PS C:\> Get-Gpo MyGPO | Set-GPOStatus -Status AllSettingsEnabled | |
.Example | |
PS C:\> Set-GpoStatus MyGPO -Status ComputerSettingsDisabled -whatif | |
.Inputs | |
String or a Group Policy object | |
.Outputs | |
None | |
.Notes | |
Credit for this function goes to Jeff Hicks: | |
http://jdhitsolutions.com/blog/2013/02/set-gpo-status-with-powershell/ | |
####################################################################### | |
# WARNING: This script has been tested function correctly in a lab environment. | |
# Use at your own risk and don't blame me if you break stuff! | |
####################################################################### | |
#> | |
[CmdletBinding(SupportsShouldProcess)] | |
Param | |
( | |
[Parameter( | |
Mandatory=$True, | |
ValueFromPipeline, | |
ValueFromPipelinebyPropertyName | |
)] | |
$DisplayName, | |
[Parameter(ValueFromPipelineByPropertyName)] | |
[ValidateSet( | |
'AllSettingsEnabled', | |
'AllSettingsDisabled', | |
'ComputerSettingsDisabled', | |
'UserSettingsDisabled' | |
)] | |
$Status, | |
[string] | |
$Domain, | |
[string] | |
$Server | |
) | |
Begin | |
{ | |
$Splat = @{ ErrorAction="Stop" } | |
if ($Domain) { $Splat.Add("Domain",$Domain) } | |
if ($Server) { $Splat.Add("Server",$Server) } | |
} | |
Process | |
{ | |
if ($Displayname -is [string]) | |
{ | |
$Splat.Add("Name",$DisplayName) | |
Try { $Gpo = Get-GPO @Splat } Catch { $_; return } | |
} | |
else | |
{ | |
$Splat.Add("GUID",$DisplayName.Id) | |
$Gpo = $DisplayName | |
} | |
if ($PSCmdlet.ShouldProcess("$($Gpo.Displayname) : $Status ")) | |
{ | |
$Gpo.GpoStatus = $Status | |
} | |
} | |
} | |
#requires -Version 3.0 | |
#requires -Module GroupPolicy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment