From b915216eb416eb463e8072209710e4427fa9d6fc Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Mon, 11 May 2020 11:50:03 +0200 Subject: [PATCH] New function Get-GPOZaurrOwner --- Public/Get-GPOZaurrOwner.ps1 | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Public/Get-GPOZaurrOwner.ps1 diff --git a/Public/Get-GPOZaurrOwner.ps1 b/Public/Get-GPOZaurrOwner.ps1 new file mode 100644 index 0000000..4ea61f4 --- /dev/null +++ b/Public/Get-GPOZaurrOwner.ps1 @@ -0,0 +1,42 @@ +function Get-GPOZaurrOwner { + [cmdletbinding()] + param( + [switch] $IncludeSysvol, + + [alias('ForestName')][string] $Forest, + [string[]] $ExcludeDomains, + [alias('Domain', 'Domains')][string[]] $IncludeDomains, + [System.Collections.IDictionary] $ExtendedForestInformation, + [System.Collections.IDictionary] $ADAdministrativeGroups + ) + Begin { + $ForestInformation = Get-WinADForestDetails -Extended -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation + if (-not $ADAdministrativeGroups) { + $ADAdministrativeGroups = Get-ADADministrativeGroups -Type DomainAdmins, EnterpriseAdmins -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation + } + } + Process { + Get-GPOZaurrAD -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ForestInformation | ForEach-Object -Process { + $ACL = Get-ADACLOwner -ADObject $_.GPODistinguishedName -Resolve -ADAdministrativeGroups $ADAdministrativeGroups + $Object = [ordered] @{ + DisplayName = $_.DisplayName + DomainName = $_.DomainName + GUID = $_.GUID + DistinguishedName = $_.GPODistinguishedName + Owner = $ACL.OwnerName + OwnerSid = $ACL.OwnerSid + OwnerType = $ACL.OwnerType + } + if ($IncludeSysvol) { + $FileOwner = Get-FileOwner -JustPath -Path $_.Path -Resolve + $Object['SysvolOwner'] = $FileOwner.OwnerName + $Object['SysvolSid'] = $FileOwner.OwnerSid + $Object['SysvolType'] = $FileOwner.OwnerType + } + [PSCUstomObject] $Object + } + } + End { + + } +} \ No newline at end of file