From 0d12bb9b05c5b4d8f326c18b3a032cb92974d88e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Fri, 10 Apr 2020 16:48:15 +0200 Subject: [PATCH] Update --- Examples/Example-08-ListingPermissions.ps1 | 16 +++++ GPOZaurr.psd1 | 2 +- Private/ConvertTo-TableFormat.ps1 | 45 +++++++++++++ Public/Get-GPOZaurrPermissions.ps1 | 75 ++++++++++++++++++++++ 4 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 Examples/Example-08-ListingPermissions.ps1 create mode 100644 Private/ConvertTo-TableFormat.ps1 create mode 100644 Public/Get-GPOZaurrPermissions.ps1 diff --git a/Examples/Example-08-ListingPermissions.ps1 b/Examples/Example-08-ListingPermissions.ps1 new file mode 100644 index 0000000..5f806f8 --- /dev/null +++ b/Examples/Example-08-ListingPermissions.ps1 @@ -0,0 +1,16 @@ +Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force + +#$GPOS = Get-GPOZaurr +#$GPOS | Format-Table -AutoSize + +#$GPOS[0] | Format-List + +#$GPOs[0].ACL | Format-Table -AutoSize + +#Get-GPOZaurrPermissions | Format-Table -AutoSize +$T = Get-GPOZaurrPermissions #| Out-HtmlView +#$T[0] | Format-List * +$T | Format-Table -AutoSize +#$T[0].Trustee +#$T[0].Permission +#$T[0] \ No newline at end of file diff --git a/GPOZaurr.psd1 b/GPOZaurr.psd1 index 7ea7073..80eeb14 100644 --- a/GPOZaurr.psd1 +++ b/GPOZaurr.psd1 @@ -5,7 +5,7 @@ CompatiblePSEditions = 'Desktop' Copyright = '(c) 2011 - 2020 Przemyslaw Klys @ Evotec. All rights reserved.' Description = 'Group Policy Eater' - FunctionsToExport = 'Backup-GPOZaurr', 'Get-GPOZaurr', 'Get-GPOZaurrBackupInformation', 'Get-GPOZaurrPassword', 'Get-GPOZaurrWMI', 'New-GPOZaurrWMI', 'Remove-GPOZaurr', 'Remove-GPOZaurrWMI', 'Restore-GPOZaurr', 'Save-GPOZaurrFiles' + FunctionsToExport = 'Backup-GPOZaurr', 'Get-GPOZaurr', 'Get-GPOZaurrBackupInformation', 'Get-GPOZaurrPassword', 'Get-GPOZaurrPermissions', 'Get-GPOZaurrWMI', 'New-GPOZaurrWMI', 'Remove-GPOZaurr', 'Remove-GPOZaurrWMI', 'Restore-GPOZaurr', 'Save-GPOZaurrFiles' GUID = 'f7d4c9e4-0298-4f51-ad77-e8e3febebbde' ModuleVersion = '0.0.6' PowerShellVersion = '5.1' diff --git a/Private/ConvertTo-TableFormat.ps1 b/Private/ConvertTo-TableFormat.ps1 new file mode 100644 index 0000000..ebd64ad --- /dev/null +++ b/Private/ConvertTo-TableFormat.ps1 @@ -0,0 +1,45 @@ +function ConvertTo-TableFormat { + <# + .SYNOPSIS + Rebuild an object based on the Format Data for the object. + .DESCRIPTION + Allows an object to be rebuilt based on the view data for the object. Uses Select-Object to create a new PSCustomObject. + #> + [CmdletBinding()] + param ( + [Parameter(ValueFromPipeline)] + [Object]$InputObject + ) + begin { + $isFirst = $true + } + process { + $format = if ($isFirst) { + $formatData = Get-FormatData -TypeName $InputObject.PSTypeNames | Select-Object -First 1 + if ($formatData) { + $viewDefinition = $formatData.FormatViewDefinition | Where-Object Control -match 'TableControl' + + for ($i = 0; $i -lt $viewDefinition.Control.Headers.Count; $i++) { + $name = $viewDefinition.Control.Headers[$i].Label + + $displayEntry = $viewDefinition.Control.Rows.Columns[$i].DisplayEntry + if (-not $name) { + $name = $displayEntry.Value + } + + $expression = switch ($displayEntry.ValueType) { + 'Property' { $displayEntry.Value } + 'ScriptBlock' { [ScriptBlock]::Create($displayEntry.Value) } + } + + @{ Name = $name; Expression = $expression } + } + } + } + if ($format) { + $InputObject | Select-Object -Property $format + } else { + $InputObject + } + } +} \ No newline at end of file diff --git a/Public/Get-GPOZaurrPermissions.ps1 b/Public/Get-GPOZaurrPermissions.ps1 new file mode 100644 index 0000000..ad43a4e --- /dev/null +++ b/Public/Get-GPOZaurrPermissions.ps1 @@ -0,0 +1,75 @@ +function Get-GPOZaurrPermissions { + [cmdletBinding()] + param( + [switch] $SkipWellKnownGroup, + [alias('ForestName')][string] $Forest, + [string[]] $ExcludeDomains, + [alias('Domain', 'Domains')][string[]] $IncludeDomains, + [System.Collections.IDictionary] $ExtendedForestInformation + ) + $ForestInformation = Get-WinADForestDetails -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation + foreach ($Domain in $ForestInformation.Domains) { + $QueryServer = $ForestInformation['QueryServers'][$Domain]['HostName'][0] + Get-GPO -All -Domain $Domain -Server $QueryServer | ForEach-Object -Process { + $GPO = $_ + + <# + DisplayName : ALL | Enable RDP + DomainName : ad.evotec.xyz + Owner : EVOTEC\Domain Admins + Id : 051bcddf-cc11-427b-bdf0-684c0a6e3ddb + GpoStatus : AllSettingsEnabled + Description : + CreationTime : 07.08.2018 12:47:44 + ModificationTime : 07.04.2020 22:09:24 + UserVersion : AD Version: 1, SysVol Version: 1 + ComputerVersion : AD Version: 1, SysVol Version: 1 + WmiFilter : + #> + Get-GPPermission -Name $GPO.DisplayName -DomainName $GPO.DomainName -All -Server $QueryServer | ForEach-Object -Process { + $GPOPermission = $_ + #$GPOPermissionFormatted = ConvertTo-TableFormat -InputObject $_ + [PSCustomObject] @{ + DisplayName = $GPO.DisplayName # : ALL | Enable RDP + GUID = $GPO.ID + DomainName = $GPO.DomainName # : ad.evotec.xyz + Enabled = $GPO.GpoStatus + Description = $GPO.Description + CreationDate = $GPO.CreationTime + ModificationTime = $GPO.ModificationTime + #Owner = $GPO.Owner # : EVOTEC\Domain Admins + #Trustee = $GPOPermission.Trustee # : Domain Admins + #TrusteeType = $GPOPermissionFormatted.TrusteeType # # : Group + Permission = $GPOPermission.Permission # : GpoEditDeleteModifySecurity + Inherited = $GPOPermission.Inherited # : False + Domain = $GPOPermission.Trustee.Domain #: EVOTEC + DistinguishedName = $GPOPermission.Trustee.DSPath #: CN = Domain Admins, CN = Users, DC = ad, DC = evotec, DC = xyz + Name = $GPOPermission.Trustee.Name #: Domain Admins + Sid = $GPOPermission.Trustee.Sid #: S - 1 - 5 - 21 - 853615985 - 2870445339 - 3163598659 - 512 + SidType = $GPOPermission.Trustee.SidType #: Group + } + } + $SplittedOwner = $GPO.Owner.Split('\') + [PSCustomObject] @{ + DisplayName = $GPO.DisplayName # : ALL | Enable RDP + GUID = $GPO.GUID + DomainName = $GPO.DomainName # : ad.evotec.xyz + #Owner = $GPO.Owner # : EVOTEC\Domain Admins + #Trustee = $GPOPermission.Trustee # : Domain Admins + #TrusteeType = $GPOPermissionFormatted.TrusteeType # # : Group + Enabled = $GPO.GpoStatus + Description = $GPO.Description + CreationDate = $GPO.CreationTime + ModificationTime = $GPO.ModificationTime + + Permission = 'Owner' # : GpoEditDeleteModifySecurity + Inherited = $false # : False + Domain = $SplittedOwner[0] #: EVOTEC + DistinguishedName = '' #: CN = Domain Admins, CN = Users, DC = ad, DC = evotec, DC = xyz + Name = $SplittedOwner[1] #: Domain Admins + Sid = '' #: S - 1 - 5 - 21 - 853615985 - 2870445339 - 3163598659 - 512 + SidType = '' #: Group + } + } + } +} \ No newline at end of file