@@ -10451,7 +10451,9 @@ Ouputs a hashtable representing the parsed GptTmpl.inf file.
10451
10451
}
10452
10452
10453
10453
Write-Verbose "[Get-GptTmpl] Parsing GptTmplPath: $TargetGptTmplPath"
10454
- Get-IniContent -Path $TargetGptTmplPath -ErrorAction Stop
10454
+ $Contents = Get-IniContent -Path $TargetGptTmplPath -ErrorAction Stop
10455
+ $Contents['Path'] = $TargetGptTmplPath
10456
+ $Contents
10455
10457
}
10456
10458
catch {
10457
10459
Write-Verbose "[Get-GptTmpl] Error parsing $TargetGptTmplPath : $_"
@@ -11862,7 +11864,7 @@ PowerView.GGPOComputerLocalGroupMember
11862
11864
}
11863
11865
11864
11866
11865
- function Get-DomainPolicy {
11867
+ function Get-DomainPolicyData {
11866
11868
<#
11867
11869
.SYNOPSIS
11868
11870
@@ -11882,9 +11884,10 @@ domain or a specified domain/domain controller using Get-DomainGPO.
11882
11884
11883
11885
The domain to query for default policies, defaults to the current domain.
11884
11886
11885
- .PARAMETER Source
11887
+ .PARAMETER Policy
11886
11888
11887
- Extract 'Domain' or 'DC' (domain controller) policies.
11889
+ Extract 'Domain' or 'DC' (domain controller) policies, otherwise queries for the particular
11890
+ GPO name or GUID.
11888
11891
11889
11892
.PARAMETER Server
11890
11893
@@ -11905,27 +11908,33 @@ for connection to the target domain.
11905
11908
11906
11909
.EXAMPLE
11907
11910
11908
- Get-DomainPolicy
11911
+ Get-DomainPolicyData
11909
11912
11910
- Returns the domain policy for the current domain.
11913
+ Returns the default domain policy for the current domain.
11911
11914
11912
11915
.EXAMPLE
11913
11916
11914
- Get-DomainPolicy -Domain dev.testlab.local
11917
+ Get-DomainPolicyData -Domain dev.testlab.local
11915
11918
11916
- Returns the domain policy for the dev.testlab.local domain.
11919
+ Returns the default domain policy for the dev.testlab.local domain.
11917
11920
11918
11921
.EXAMPLE
11919
11922
11920
- Get-DomainPolicy -Source DC -Domain dev.testlab.local
11923
+ Get-DomainGPO | Get-DomainPolicy
11924
+
11925
+ Parses any GptTmpl.infs found for any policies.
11926
+
11927
+ .EXAMPLE
11928
+
11929
+ Get-DomainPolicyData -Policy DC -Domain dev.testlab.local
11921
11930
11922
11931
Returns the policy for the dev.testlab.local domain controller.
11923
11932
11924
11933
.EXAMPLE
11925
11934
11926
11935
$SecPassword = ConvertTo-SecureString 'Password123!' -AsPlainText -Force
11927
11936
$Cred = New-Object System.Management.Automation.PSCredential('TESTLAB\dfm.a', $SecPassword)
11928
- Get-DomainPolicy -Credential $Cred
11937
+ Get-DomainPolicyData -Credential $Cred
11929
11938
11930
11939
.OUTPUTS
11931
11940
@@ -11939,14 +11948,13 @@ Ouputs a hashtable representing the parsed GptTmpl.inf file.
11939
11948
[CmdletBinding()]
11940
11949
Param(
11941
11950
[Parameter(Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
11942
- [Alias('Name')]
11943
- [ValidateNotNullOrEmpty()]
11951
+ [Alias('Source', 'Name')]
11944
11952
[String]
11945
- $Domain,
11953
+ $Policy = ' Domain' ,
11946
11954
11947
- [ValidateSet('Domain', 'DC', 'DomainController' )]
11955
+ [ValidateNotNullOrEmpty( )]
11948
11956
[String]
11949
- $Source = ' Domain' ,
11957
+ $Domain,
11950
11958
11951
11959
[ValidateNotNullOrEmpty()]
11952
11960
[Alias('DomainController')]
@@ -11982,56 +11990,49 @@ Ouputs a hashtable representing the parsed GptTmpl.inf file.
11982
11990
$ConvertArguments['Domain'] = $Domain
11983
11991
}
11984
11992
11985
- if ($Source -eq 'Domain') {
11986
- # query the given domain for the default domain policy object (name = {31B2F340-016D-11D2-945F-00C04FB984F9})
11993
+ if ($Policy -eq 'Domain') {
11987
11994
$SearcherArguments['Identity'] = '{31B2F340-016D-11D2-945F-00C04FB984F9}'
11988
- $GPO = Get-DomainGPO @SearcherArguments
11989
-
11990
- if ($GPO) {
11991
- # grab the GptTmpl.inf file and parse it
11992
- $GptTmplPath = $GPO.gpcfilesyspath + '\MACHINE\Microsoft\Windows NT\SecEdit\GptTmpl.inf'
11993
- $ParseArgs = @{'GptTmplPath' = $GptTmplPath}
11994
- if ($PSBoundParameters['Credential']) { $ParseArgs['Credential'] = $Credential }
11995
- Get-GptTmpl @ParseArgs
11996
- }
11997
11995
}
11998
- else {
11999
- # query the given domain/dc for the default domain controller policy object (name = {6AC1786C-016F-11D2-945F-00C04FB984F9})
11996
+ elseif (($Policy -eq 'DomainController') -or ($Policy -eq 'DC')) {
12000
11997
$SearcherArguments['Identity'] = '{6AC1786C-016F-11D2-945F-00C04FB984F9}'
12001
- $GPO = Get-DomainGPO @SearcherArguments
12002
-
12003
- if ($GPO) {
12004
- # grab the GptTmpl.inf file and parse it
12005
- $GptTmplPath = $GPO.gpcfilesyspath + "\MACHINE\Microsoft\Windows NT\SecEdit\GptTmpl.inf"
12006
-
12007
- $ParseArgs = @{'GptTmplPath' = $GptTmplPath}
12008
- if ($PSBoundParameters['Credential']) { $ParseArgs['Credential'] = $Credential }
12009
-
12010
- # parse the GptTmpl.inf
12011
- Get-GptTmpl @ParseArgs | ForEach-Object {
12012
- if ($PSBoundParameters['ResolveSids']) {
12013
- $Root = $_
12014
- $PrivilegeRightsResovled = @{}
12015
- # if we're resolving sids in PrivilegeRights to names
12016
- if ($Root.'Privilege Rights') {
12017
- $PrivilegeRights = $Root.'Privilege Rights'
12018
- ForEach ($PrivilegeRight in $PrivilegeRights.Keys) {
12019
- $PrivilegeRightsResovled[$PrivilegeRight] = $PrivilegeRights."$PrivilegeRight" | ForEach-Object {
12020
- try {
12021
- $_ | ForEach-Object { ConvertFrom-SID -ObjectSid ($_.Trim('*')) @ConvertArguments }
12022
- }
12023
- catch {
12024
- Write-Verbose "[Get-DomainPolicy] Error resolving SID : $_"
12025
- $_
12026
- }
11998
+ }
11999
+ else {
12000
+ $SearcherArguments['Identity'] = $Policy
12001
+ }
12002
+
12003
+ $GPO = Get-DomainGPO @SearcherArguments
12004
+
12005
+ if ($GPO) {
12006
+ # grab the GptTmpl.inf file and parse it
12007
+ $GptTmplPath = $GPO.gpcfilesyspath + "\MACHINE\Microsoft\Windows NT\SecEdit\GptTmpl.inf"
12008
+
12009
+ $ParseArgs = @{'GptTmplPath' = $GptTmplPath}
12010
+ if ($PSBoundParameters['Credential']) { $ParseArgs['Credential'] = $Credential }
12011
+
12012
+ # parse the GptTmpl.inf
12013
+ Get-GptTmpl @ParseArgs | ForEach-Object {
12014
+ if ($PSBoundParameters['ResolveSids']) {
12015
+ $Root = $_
12016
+ $PrivilegeRightsResovled = @{}
12017
+ # if we're resolving sids in PrivilegeRights to names
12018
+ if ($Root.'Privilege Rights') {
12019
+ $PrivilegeRights = $Root.'Privilege Rights'
12020
+ ForEach ($PrivilegeRight in $PrivilegeRights.Keys) {
12021
+ $PrivilegeRightsResovled[$PrivilegeRight] = $PrivilegeRights."$PrivilegeRight" | ForEach-Object {
12022
+ try {
12023
+ $_ | ForEach-Object { ConvertFrom-SID -ObjectSid ($_.Trim('*')) @ConvertArguments }
12024
+ }
12025
+ catch {
12026
+ Write-Verbose "[Get-DomainPolicy] Error resolving SID : $_"
12027
+ $_
12027
12028
}
12028
12029
}
12029
12030
}
12030
- $Root.'Privilege Rights' = $PrivilegeRightsResovled
12031
- $Root
12032
12031
}
12033
- else { $_ }
12032
+ $Root.'Privilege Rights' = $PrivilegeRightsResovled
12033
+ $Root
12034
12034
}
12035
+ else { $_ }
12035
12036
}
12036
12037
}
12037
12038
}
@@ -18663,3 +18664,4 @@ Set-Alias Get-NetForestTrust Get-ForestTrust
18663
18664
Set-Alias Find-ForeignUser Get-DomainForeignUser
18664
18665
Set-Alias Find-ForeignGroup Get-DomainForeignGroupMember
18665
18666
Set-Alias Invoke-MapDomainTrust Get-DomainTrustMapping
18667
+ Set-Alias Get-DomainPolicy Get-DomainPolicyData
0 commit comments