-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 67b2791
Showing
42 changed files
with
13,535 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_Test/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
function Convert-GPONameToID { | ||
Param ( | ||
[Parameter(Mandatory)] | ||
[string]$Name | ||
) | ||
|
||
$Filter = '(&(objectClass=groupPolicyContainer)(displayName={0}))' -f $Name | ||
$DomainDN = ([System.DirectoryServices.DirectoryEntry]::new('LDAP://RootDSE')).defaultNamingContext | ||
$PoliciesCNLDAPPath = 'LDAP://CN=Policies,CN=System,{0}' -f $DomainDN[0] # $DomainDN is a collection of a System.DirectoryServices.ResultPropertyValueCollection type with a single element inside it | ||
$PoliciesDSE = [System.DirectoryServices.DirectoryEntry]::new($PoliciesCNLDAPPath) | ||
|
||
$Searcher = [System.DirectoryServices.DirectorySearcher]::new($PoliciesDSE, $Filter, 'cn', 'OneLevel') | ||
$Result = $Searcher.FindOne() # $Result is also a collection of a System.DirectoryServices.ResultPropertyValueCollection type | ||
[guid]$Result.Properties.cn[0] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function Get-GPPSection { | ||
Param ( | ||
[Parameter(ParameterSetName = 'ByName', Mandatory)] | ||
[string]$GPOName, | ||
[Parameter(ParameterSetName = 'ById', Mandatory)] | ||
[guid]$GPOId, | ||
[Parameter(ParameterSetName = 'ByName')] | ||
[Parameter(ParameterSetName = 'ById')] | ||
[GPPContext]$Context = $ModuleWideDefaultGPPContext, | ||
[Parameter(ParameterSetName = 'ByName', Mandatory)] | ||
[Parameter(ParameterSetName = 'ById', Mandatory)] | ||
[GPPType]$Type | ||
) | ||
|
||
if (-not $GPOId) { | ||
$GPOId = Convert-GPONameToID -Name $GPOName | ||
} | ||
|
||
$FilePath = Get-GPPSectionFilePath -GPOId $GPOId -Context $Context -Type $Type | ||
|
||
$FilePathExistence = Test-Path -Path $FilePath | ||
if ($FilePathExistence) { | ||
[xml]$XmlDocument = Get-Content -Path $FilePath | ||
|
||
Deserialize-GPPSection -InputObject $XmlDocument | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function Get-GPPSectionFilePath { | ||
Param ( | ||
[Parameter(Mandatory)] | ||
[guid]$GPOId, | ||
[Parameter(Mandatory)] | ||
[GPPContext]$Context, | ||
[Parameter(Mandatory)] | ||
[GPPType]$Type | ||
) | ||
|
||
$DomainName = (Get-CimInstance -ClassName 'Win32_ComputerSystem').Domain # Computer's domain name, not user's | ||
$PoliciesFolderPath = '\\{0}\SYSVOL\{0}\Policies' -f $DomainName | ||
$PolicyPath = Join-Path -Path $PoliciesFolderPath -ChildPath $GPOId.ToString('B') # B - 32 digits separated by hyphens, enclosed in braces: {00000000 - 0000 - 0000 - 0000 - 000000000000} | ||
$ContextPath = Join-Path -Path $PolicyPath -ChildPath ('{0}\Preferences' -f $Context) | ||
Join-Path -Path $ContextPath -ChildPath ('{0}\{0}.xml' -f $Type) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function Set-GPPSection { | ||
Param ( | ||
[Parameter(ParameterSetName = 'ByName', Mandatory)] | ||
[Parameter(ParameterSetName = 'ById', Mandatory)] | ||
[GPPSection]$InputObject, | ||
[Parameter(ParameterSetName = 'ByName', Mandatory)] | ||
[string]$GPOName, | ||
[Parameter(ParameterSetName = 'ById', Mandatory)] | ||
[guid]$GPOId, | ||
[Parameter(ParameterSetName = 'ByName')] | ||
[Parameter(ParameterSetName = 'ById')] | ||
[GPPContext]$Context = $ModuleWideDefaultGPPContext, | ||
[Parameter(ParameterSetName = 'ByName', Mandatory)] | ||
[Parameter(ParameterSetName = 'ById', Mandatory)] | ||
[GPPType]$Type | ||
) | ||
|
||
if (-not $GPOId) { | ||
$GPOId = Convert-GPONameToID -Name $GPOName | ||
} | ||
|
||
$SectionDescription = Serialize-GPPSection -InputObject $InputObject -IncludeType | ||
|
||
$XMLDocument = $SectionDescription.XMLDocument | ||
$Type = $SectionDescription.Type | ||
|
||
$FilePath = Get-GPPSectionFilePath -GPOId $GPOId -Context $Context -Type $Type | ||
|
||
Set-Content -Path $FilePath -Value $XMLDocument.OuterXml | ||
} |
Oops, something went wrong.