Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review PR #1

Open
wants to merge 15 commits into
base: reviewBase
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DSCResource.Tests
64 changes: 64 additions & 0 deletions DSCResources/Helper.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<#
.SYNOPSIS
Tests the $Target parameter to ensure it contains the RootDSE and adds it if it doesn't.

.PARAMETER Target
The target OU Distinguished Name with or without the RootDSE.

.PARAMETER Domain
Not used. Included to allow @PSBoundParameters in function call.

.PARAMETER Server
The name of the server. Optional.

.PARAMETER Ensure
Not used. Included to allow @PSBoundParameters in function call.

#>
function Test-TargetDN
{
param
(
[parameter(Mandatory = $true)]
[string]
$Target,

[string]
$Domain,

[string]
$Server,

[ValidateSet('Present','Absent')]
[string]
$Ensure = 'Present'
)

$getADDomainParams = @{}
if ($Server)
{
$getADDomainParams += @{
Server = $Server
}
}
Write-Verbose -Message ("Checking the Domain Distinguished Name is " +
"present on the Target Distinguished Name.")
$domainDN = (Get-ADDomain @getADDomainParams).DistinguishedName
if ($Target -like "*$domainDN")
{
Write-Verbose -Message "Target has full DN."
}
else
{
Write-Verbose -Message "Adding the Domain Distinguished Name to the Target DN."
if ($Target.EndsWith(","))
{
$Target = "$Target$domainDN"
}
else
{
$Target = "$Target,$domainDN"
}
}
Write-Output -InputObject $Target
}
156 changes: 156 additions & 0 deletions DSCResources/MSFT_GPInheritance/MSFT_GPInheritance.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
function Get-TargetResource
{
[OutputType([Hashtable])]
param
(
[parameter(Mandatory = $true)]
[string]
$Target,

[string]
$Domain,

[string]
$Server,

[ValidateSet('Present','Absent')]
[string]
$Ensure = 'Present'
)

Import-Module $PSScriptRoot\..\Helper.psm1 -Verbose:$false
Import-Module -Name GroupPolicy -Verbose:$false
$Target = Test-TargetDN @PSBoundParameters
$targetResource = @{
Target = $Target
Domain = $null
Server = $null
Ensure = $null
}
$getGPInheritanceParams = @{
Target = $Target
}
if ($Domain)
{
$targetResource.Domain = $Domain
$getGPInheritanceParams += @{
Domain = $Domain
}
}
if ($Server)
{
$targetResource.Server = $Server
$getGPInheritanceParams += @{
Server = $Server
}
}
Write-Verbose -Message 'Getting Group Policy Inheritance'
$gpoInheritanceBlocked = (Get-GPInheritance @getGPInheritanceParams).GpoInheritanceBlocked
if (!$gpoInheritanceBlocked)
{
$targetResource.Ensure = 'Present'
}
else
{
$targetResource.Ensure = 'Absent'
}
Write-Output -InputObject $targetResource
}

function Set-TargetResource
{
param
(
[parameter(Mandatory = $true)]
[string]
$Target,

[string]
$Domain,

[string]
$Server,

[ValidateSet('Present','Absent')]
[string]
$Ensure = 'Present'
)

if ($Ensure -eq 'Present')
{
Write-Verbose -Message 'Enabling Group Policy Inheritance'
$isBlocked = 'No'
}
else
{
Write-Verbose -Message 'Disabling Group Policy Inheritance'
$isBlocked = 'Yes'
}
$Target = Test-TargetDN @PSBoundParameters
$setGPInheritanceParams = @{
Target = $Target
IsBlocked = $IsBlocked
}
if ($Domain)
{
$setGPInheritanceParams += @{
Domain = $Domain
}
}
if ($Server)
{
$setGPInheritanceParams += @{
Server = $Server
}
}
Import-Module -Name GroupPolicy -Verbose:$false
$null = Set-GPInheritance @setGPInheritanceParams
}

function Test-TargetResource
{
[OutputType([Boolean])]
param
(
[parameter(Mandatory = $true)]
[string]
$Target,

[string]
$Domain,

[string]
$Server,

[ValidateSet('Present','Absent')]
[string]
$Ensure = 'Present'
)

$targetResource = Get-TargetResource @PSBoundParameters
switch ($Ensure)
{
Present
{
if ($targetResource.Ensure -eq 'Present')
{
Write-Output -InputObject $true
}
else
{
Write-Output -InputObject $false
}
}
Absent
{
if ($targetResource.Ensure -eq 'Absent')
{
Write-Output -InputObject $true
}
else
{
Write-Output -InputObject $false
}
}
}
}
8 changes: 8 additions & 0 deletions DSCResources/MSFT_GPInheritance/MSFT_GPInheritance.schema.mof
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[ClassVersion("1.0.0"), FriendlyName("GPInheritance")]
class MSFT_GPInheritance : OMI_BaseResource
{
[Key] String Target;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add descriptions

[write] String Domain;
[write] String Server;
[write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
};
Loading