From 8950956169d07e417d79f65d906aa8eb31153aec Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Sat, 5 Dec 2020 00:12:15 +0100 Subject: [PATCH] Set-GPOZaurrStatus added --- Public/Set-GPOZaurrStatus.ps1 | 81 +++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Public/Set-GPOZaurrStatus.ps1 diff --git a/Public/Set-GPOZaurrStatus.ps1 b/Public/Set-GPOZaurrStatus.ps1 new file mode 100644 index 0000000..e599693 --- /dev/null +++ b/Public/Set-GPOZaurrStatus.ps1 @@ -0,0 +1,81 @@ +function Set-GPOZaurrStatus { + <# + .SYNOPSIS + Enables or disables user/computer section of Group Policy. + + .DESCRIPTION + Enables or disables user/computer section of Group Policy. + + .PARAMETER GPOName + Provide Group Policy Name + + .PARAMETER GPOGuid + Provide Group Policy GUID + + .PARAMETER Status + Choose a status for provided Group Policy + + .PARAMETER Forest + Choose forest to target. + + .PARAMETER ExcludeDomains + Exclude domains from trying to find Group Policy Name or GUID + + .PARAMETER IncludeDomains + Include domain (one or more) to find Group Policy Name or GUID + + .PARAMETER ExtendedForestInformation + Provide Extended Forest Information + + .EXAMPLE + An example + + .NOTES + General notes + #> + [cmdletBinding(SupportsShouldProcess, DefaultParameterSetName = 'GPOName')] + param( + [alias('Name', 'DisplayName')][Parameter(ParameterSetName = 'GPOName', Mandatory)][string] $GPOName, + [Parameter(ParameterSetName = 'GPOGUID', Mandatory)][alias('GUID', 'GPOID')][string] $GPOGuid, + [Parameter(Mandatory)][Microsoft.GroupPolicy.GpoStatus] $Status, + + [alias('ForestName')][string] $Forest, + [string[]] $ExcludeDomains, + [alias('Domain', 'Domains')][string[]] $IncludeDomains, + [System.Collections.IDictionary] $ExtendedForestInformation + ) + Begin { + + } + Process { + $getGPOZaurrSplat = @{ + Forest = $Forest + IncludeDomains = $IncludeDomains + ExcludeDomains = $ExcludeDomains + ExtendedForestInformation = $ExtendedForestInformation + GpoName = $GPOName + GPOGUID = $GPOGuid + } + Remove-EmptyValue -Hashtable $getGPOZaurrSplat + Get-GPOZaurr @getGPOZaurrSplat | ForEach-Object { + $GPO = $_ + + if ($Status -eq [Microsoft.GroupPolicy.GpoStatus]::AllSettingsEnabled) { + $Text = "Enabling computer and user settings in domain $($GPO.DomainName)" + } elseif ($Status -eq [Microsoft.GroupPolicy.GpoStatus]::ComputerSettingsDisabled) { + $Text = "Disabling computer setings in domain $($GPO.DomainName)" + } elseif ($Status -eq [Microsoft.GroupPolicy.GpoStatus]::UserSettingsDisabled) { + $Text = "Disabling user setings in domain $($GPO.DomainName)" + } else { + $Text = "Disabling computer user settings in domain $($GPO.DomainName)" + } + if ($PSCmdlet.ShouldProcess($GPO.DisplayName, $Text)) { + try { + $GPO.GPOObject.GpoStatus = $Status + } catch { + Write-Warning -Message "Set-GPOZaurrStatus - Couldn't set $($GPO.DisplayName) / $($GPO.DomainName) to $Status. Error $($_.Exception.Message)" + } + } + } + } +} \ No newline at end of file