Compare commits

...

15 Commits

Author SHA1 Message Date
Przemyslaw Klys 4acf509e2b Update 2020-05-26 19:16:32 +02:00
Przemyslaw Klys 4c0647b81f Remove Orphaned Sysvol Folders 2020-05-26 19:03:21 +02:00
Przemyslaw Klys 7415386a13 Update WMI filter 2020-05-26 18:32:06 +02:00
Przemyslaw Klys db7838fc18 Update SYSVOL/WMI 2020-05-26 18:31:57 +02:00
Przemyslaw Klys 19e6d514a1 Update psd1 2020-05-25 18:34:10 +02:00
Przemyslaw Klys 3375c10ee7 Update 2020-05-25 18:33:49 +02:00
Przemyslaw Klys ca030b5fee Improved function 2020-05-25 18:03:44 +02:00
Przemyslaw Klys 30660a9097 Update PSD1 2020-05-25 14:42:16 +02:00
Przemyslaw Klys 3e9848e705 Updates to functions 2020-05-25 14:40:59 +02:00
Przemyslaw Klys e04f5514f8 Cleanup dead code 2020-05-15 13:31:13 +02:00
Przemyslaw Klys 02dbe6c02c Small cleanup 2020-05-15 12:18:46 +02:00
Przemyslaw Klys 5959f31607 PSD1 update 2020-05-15 11:20:42 +02:00
Przemyslaw Klys 971f5a18e3 Update GPOZaurrAD 2020-05-15 11:20:03 +02:00
Przemyslaw Klys 6e81f6f80f More work 2020-05-14 22:27:48 +02:00
Przemyslaw Klys 6c607b28f3 Update PSD1 2020-05-14 17:43:12 +02:00
21 changed files with 340 additions and 360 deletions
@@ -0,0 +1,3 @@
Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force
Get-GPOZaurrWMI -Name 'Test - Dual Filter' | Format-Table -AutoSize *
@@ -0,0 +1,19 @@
Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force
# Step 1 - Create report
$Report = Get-GPOZaurrPermission -Type All
$Report | ConvertTo-Excel -FilePath $Env:UserProfile\Desktop\GPOOutput.xlsx -ExcelWorkSheetName 'GPO Permissions Before' -AutoFilter -AutoFit
# Step 2 - Verify couple of GPOS returned with whatif
#Remove-GPOZaurrPermission -Verbose -Type Unknown -LimitProcessing 4 -WhatIf
# Step 3 - Confirm the change without whatif
#Remove-GPOZaurrPermission -Verbose -Type Unknown -LimitProcessing 4
# Step 4 - Analyze GPO manually to confirm only unknown sids were removed
# Step 5 - if everything went ok, continue process without whatif
# Step-6 - Generate new report
#$Report = Get-GPOZaurrPermission -Type All
#$Report | ConvertTo-Excel -FilePath $Env:UserProfile\Desktop\GPOOutput.xlsx -ExcelWorkSheetName 'GPO Permissions After' -AutoFilter -AutoFit
+12
View File
@@ -0,0 +1,12 @@
Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force
# Step 1 - Create report
$Report = Get-GPOZaurrOwner -IncludeSysvol
$Report | ConvertTo-Excel -FilePath $Env:UserProfile\Desktop\GPOOwners.xlsx -ExcelWorkSheetName 'GPO Owners Before' -AutoFilter -AutoFit
# Step 2 - Fix owners / use WhatIf and LimitProcessing / verify changes before/after
Set-GPOZaurrOwner -Type NotAdministrative -Verbose -LimitProcessing 2 -WhatIf
# Step 3
$Report = Get-GPOZaurrOwner -IncludeSysvol
$Report | ConvertTo-Excel -FilePath $Env:UserProfile\Desktop\GPOOwners.xlsx -ExcelWorkSheetName 'GPO Owners After' -AutoFilter -AutoFit
+1 -2
View File
@@ -1,10 +1,9 @@
Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force
$T = Get-GPOZaurrOwner -Verbose -IncludeSysvol -Forest 'test.evotec.pl'
$T = Get-GPOZaurrOwner -Verbose -IncludeSysvol
$T | Format-Table *
#$T | Out-HtmlView -ScrollX
return
$T = Get-GPOZaurrOwner -Verbose -IncludeSysvol -GPOName 'Default Domain Policy'
$T | Format-Table *
@@ -2,4 +2,4 @@
Get-GPOZaurrPermissionConsistency -GPOName 'Default Domain Controllers Policy' -IncludeDomains 'ad.evotec.xyz'
Repair-GPOZaurrPermissionConsistency -GPOName 'Default Domain Controllers Policy' -IncludeDomains 'ad.evotec.xyz' #-WhatIf -Verbose
Repair-GPOZaurrPermissionConsistency -GPOName 'Default Domain Controllers Policy' -IncludeDomains 'ad.evotec.xyz' -Verbose #-WhatIf -Verbose
@@ -1,9 +1,9 @@
Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force
#Get-GPOZaurrPermissionConsistency -Type All -Forest 'test.evotec.pl' | Format-Table
$Output = Get-GPOZaurrPermissionConsistency -GPOName 'Default Domain Controllers Policy' -IncludeDomains 'ad.evotec.xyz' -VerifyInside
$Output = Get-GPOZaurrPermissionConsistency -GPOName 'Default Domain Controllers Policy' -IncludeDomains 'ad.evotec.xyz' -VerifyInheritance
$Output | Format-Table DisplayName, DomainName, ACLConsistent, ACLConsistentInside
$Output.ACLConsistentInsideDetails | Format-Table
$Output = Get-GPOZaurrPermissionConsistency -VerifyInside -Type 'All'
$Output = Get-GPOZaurrPermissionConsistency -VerifyInheritance -Type 'All'
$Output | Format-Table
+3
View File
@@ -0,0 +1,3 @@
Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force
Get-GPOZaurrSysvol -Verbose | Format-Table
@@ -0,0 +1,3 @@
Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force
Get-GPOZaurrSysvol -VerifyDomainControllers -Verbose | Format-Table *
@@ -0,0 +1,7 @@
Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force
# this allows you to process X amount of orphaned folders/files (good for testing)
Remove-GPOZaurrOrphanedSysvolFolders -Verbose -WhatIf -LimitProcessing 2
# this runs for whole SYSVOL and checks things against GPOS
Remove-GPOZaurrOrphanedSysvolFolders -Verbose -WhatIf
+4 -4
View File
@@ -5,9 +5,9 @@
CompatiblePSEditions = 'Desktop'
Copyright = '(c) 2011 - 2020 Przemyslaw Klys @ Evotec. All rights reserved.'
Description = 'Group Policy Eater'
FunctionsToExport = 'Add-GPOPermission', 'Add-GPOZaurrPermission', 'Backup-GPOZaurr', 'Get-GPOZaurr', 'Get-GPOZaurrAD', 'Get-GPOZaurrBackupInformation', 'Get-GPOZaurrLink', 'Get-GPOZaurrOwner', 'Get-GPOZaurrPassword', 'Get-GPOZaurrPermission', 'Get-GPOZaurrPermissionConsistency', 'Get-GPOZaurrWMI', 'Invoke-GPOZaurrPermission', 'New-GPOZaurrWMI', 'Remove-GPOPermission', 'Remove-GPOZaurr', 'Remove-GPOZaurrPermission', 'Remove-GPOZaurrWMI', 'Repair-GPOZaurrPermissionConsistency', 'Restore-GPOZaurr', 'Save-GPOZaurrFiles', 'Set-GPOOwner', 'Set-GPOZaurrOwner'
FunctionsToExport = 'Add-GPOPermission', 'Add-GPOZaurrPermission', 'Backup-GPOZaurr', 'Get-GPOZaurr', 'Get-GPOZaurrAD', 'Get-GPOZaurrBackupInformation', 'Get-GPOZaurrLink', 'Get-GPOZaurrOwner', 'Get-GPOZaurrPassword', 'Get-GPOZaurrPermission', 'Get-GPOZaurrPermissionConsistency', 'Get-GPOZaurrSysvol', 'Get-WMIFilter', 'Get-GPOZaurrWMI', 'Invoke-GPOZaurrPermission', 'New-GPOZaurrWMI', 'Remove-GPOPermission', 'Remove-GPOZaurr', 'Remove-GPOZaurrOrphanedSysvolFolders', 'Remove-GPOZaurrPermission', 'Remove-GPOZaurrWMI', 'Repair-GPOZaurrPermissionConsistency', 'Restore-GPOZaurr', 'Save-GPOZaurrFiles', 'Set-GPOOwner', 'Set-GPOZaurrOwner'
GUID = 'f7d4c9e4-0298-4f51-ad77-e8e3febebbde'
ModuleVersion = '0.0.24'
ModuleVersion = '0.0.31'
PowerShellVersion = '5.1'
PrivateData = @{
PSData = @{
@@ -17,11 +17,11 @@
}
}
RequiredModules = @{
ModuleVersion = '0.0.141'
ModuleVersion = '0.0.143'
ModuleName = 'PSSharedGoods'
Guid = 'ee272aa8-baaa-4edf-9f45-b6d6f7d844fe'
}, @{
ModuleVersion = '0.0.55'
ModuleVersion = '0.0.57'
ModuleName = 'ADEssentials'
Guid = '9fc9fd61-7f11-4f4b-a527-084086f1905f'
}, 'ActiveDirectory', 'GroupPolicy', 'CimCmdlets', 'Microsoft.PowerShell.Management', 'Microsoft.PowerShell.Utility'
+119
View File
@@ -0,0 +1,119 @@
function Test-SysVolFolders {
[cmdletBinding()]
param(
[Array] $GPOs,
[string] $Server,
[string] $Domain
)
$Differences = @{ }
$SysvolHash = @{ }
$GPOGUIDS = $GPOs.ID.GUID
try {
$SYSVOL = Get-ChildItem -Path "\\$($Server)\SYSVOL\$Domain\Policies" -ErrorAction Stop
} catch {
$Sysvol = $Null
}
foreach ($_ in $SYSVOL) {
$GUID = $_.Name -replace '{' -replace '}'
$SysvolHash[$GUID] = $_
}
$Files = $SYSVOL.Name -replace '{' -replace '}'
if ($Files) {
$Comparing = Compare-Object -ReferenceObject $GPOGUIDS -DifferenceObject $Files -IncludeEqual
foreach ($_ in $Comparing) {
if ($_.SideIndicator -eq '==') {
$Found = 'Exists'
} elseif ($_.SideIndicator -eq '<=') {
$Found = 'Not available on SYSVOL'
} elseif ($_.SideIndicator -eq '=>') {
$Found = 'Orphaned GPO'
} else {
$Found = 'Orphaned GPO'
}
$Differences[$_.InputObject] = $Found
}
}
$GPOSummary = @(
foreach ($GPO in $GPOS) {
if ($null -ne $SysvolHash[$GPO.Id.GUID].FullName) {
$FullPath = $SysvolHash[$GPO.Id.GUID].FullName
try {
$ACL = Get-Acl -Path $SysvolHash[$GPO.Id.GUID].FullName -ErrorAction Stop
$Owner = $ACL.Owner
$ErrorMessage = ''
} catch {
Write-Warning "Get-GPOZaurrSysvol - ACL reading (1) failed for $FullPath with error: $($_.Exception.Message)"
$ACL = $null
$Owner = ''
$ErrorMessage = $_.Exception.Message
}
} else {
$ACL = $null
}
if ($null -eq $Differences[$GPO.Id.Guid]) {
$SysVolStatus = 'Not available on SYSVOL'
} else {
$SysVolStatus = $Differences[$GPO.Id.Guid]
}
[PSCustomObject] @{
DisplayName = $GPO.DisplayName
Status = $Differences[$GPO.Id.Guid]
DomainName = $GPO.DomainName
SysvolServer = $Server
SysvolStatus = $SysVolStatus
Owner = $GPO.Owner
FileOwner = $Owner
Id = $GPO.Id.Guid
GpoStatus = $GPO.GpoStatus
Path = $FullPath
Description = $GPO.Description
CreationTime = $GPO.CreationTime
ModificationTime = $GPO.ModificationTime
UserVersion = $GPO.UserVersion
ComputerVersion = $GPO.ComputerVersion
WmiFilter = $GPO.WmiFilter
Error = $ErrorMessage
}
}
# Now we need to list thru Sysvol files and fine those that do not exists as GPO and create dummy GPO objects to show orphaned gpos
foreach ($_ in $Differences.Keys) {
if ($Differences[$_] -eq 'Orphaned GPO') {
if ($SysvolHash[$_].BaseName -notcontains 'PolicyDefinitions') {
$FullPath = $SysvolHash[$_].FullName
try {
$ACL = Get-Acl -Path $FullPath -ErrorAction Stop
$Owner = $ACL.Owner
$ErrorMessage = ''
} catch {
Write-Warning "Get-GPOZaurrSysvol - ACL reading (2) failed for $FullPath with error: $($_.Exception.Message)"
$ACL = $null
$Owner = $null
$ErrorMessage = $_.Exception.Message
}
[PSCustomObject] @{
DisplayName = $SysvolHash[$_].BaseName
Status = 'Orphaned GPO'
DomainName = $Domain
SysvolServer = $Server
SysvolStatus = $Differences[$GPO.Id.Guid]
Owner = ''
FileOwner = $Owner
Id = $_
GpoStatus = 'Orphaned'
Path = $FullPath
Description = $null
CreationTime = $SysvolHash[$_].CreationTime
ModificationTime = $SysvolHash[$_].LastWriteTime
UserVersion = $null
ComputerVersion = $null
WmiFilter = $null
Error = $ErrorMessage
}
}
}
}
)
$GPOSummary | Sort-Object -Property DisplayName
}
+1 -30
View File
@@ -48,22 +48,9 @@
Server = $ForestInformation['QueryServers'][$Domain]['HostName'][0]
}
}
Get-ADObject @Splat -Properties DisplayName, Name, Created, Modified, gPCFileSysPath, gPCFunctionalityVersion, gPCWQLFilter, gPCMachineExtensionNames, Description, CanonicalName, DistinguishedName | ForEach-Object -Process { #, Deleted -IncludeDeletedObjects
#if ($_) {
Get-ADObject @Splat -Properties DisplayName, Name, Created, Modified, gPCFileSysPath, gPCFunctionalityVersion, gPCWQLFilter, gPCMachineExtensionNames, Description, CanonicalName, DistinguishedName | ForEach-Object -Process {
$DomainCN = ConvertFrom-DistinguishedName -DistinguishedName $_.DistinguishedName -ToDomainCN
$Output = [ordered]@{ }
<#
$Search = -join ($DomainCN, $Output['Guid'])
if ($GPOCache -and -not $Limited) {
$Output['DisplayName'] = $GPOCache[$Search].DisplayName
$Output['DomainName'] = $GPOCache[$Search].DomainName
$Output['Owner'] = $GPOCache[$Search].Owner
$Output['GpoStatus'] = $GPOCache[$Search].GpoStatus
$Output['Description'] = $GPOCache[$Search].Description
$Output['CreationTime'] = $GPOCache[$Search].CreationTime
$Output['ModificationTime'] = $GPOCache[$Search].ModificationTime
}
#>
$Output['DisplayName'] = $_.DisplayName
$Output['DomainName'] = $DomainCN
$Output['Description'] = $_.Description
@@ -76,22 +63,6 @@
$Output['GPODomainDistinguishedName'] = ConvertFrom-DistinguishedName -DistinguishedName $_.DistinguishedName -ToDC
$Output['GPODistinguishedName'] = $_.DistinguishedName
[PSCustomObject] $Output
<#
CanonicalName : ad.evotec.xyz/System/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}
Created : 20.05.2018 09:55:29
Description :
DisplayName : Default Domain Policy
DistinguishedName : CN={31B2F340-016D-11D2-945F-00C04FB984F9},CN=Policies,CN=System,DC=ad,DC=evotec,DC=xyz
gPCFileSysPath : \\ad.evotec.xyz\sysvol\ad.evotec.xyz\Policies\{31B2F340-016D-11D2-945F-00C04FB984F9}
gPCFunctionalityVersion : 2
gPCMachineExtensionNames : [{35378EAC-683F-11D2-A89A-00C04FBBCFA2}{53D6AB1B-2488-11D1-A28C-00C04FB94F17}][{827D319E-6EAC-11D2-A4EA-00C04F79F83A}{803E14A0-B4FB-11D0-A0D0-00A0C90F574B}][{B1BE8D72-6EAC-11D2-A4EA-00C04F79F83A}{53D6AB1B-2488-11D1-A28C-00C04FB94F17}]
Modified : 26.04.2020 18:53:56
Name : {31B2F340-016D-11D2-945F-00C04FB984F9}
ObjectClass : groupPolicyContainer
ObjectGUID : 679a6dd9-30fb-438c-a35f-e5fe8167703e
#>
#}
}
}
}
+10 -5
View File
@@ -7,7 +7,7 @@
[parameter(ParameterSetName = 'Filter')][string] $SearchBase,
[parameter(ParameterSetName = 'Filter')][Microsoft.ActiveDirectory.Management.ADSearchScope] $SearchScope,
[parameter(ParameterSetName = 'Linked',Mandatory)][validateset('Root', 'DomainControllers', 'Site', 'Other')][string] $Linked,
[parameter(ParameterSetName = 'Linked', Mandatory)][validateset('Root', 'DomainControllers', 'Site', 'Other')][string] $Linked,
[parameter(ParameterSetName = 'Filter')]
[parameter(ParameterSetName = 'ADObject')]
@@ -58,7 +58,7 @@
$Splat = @{
#Filter = $Filter
Properties = 'distinguishedName', 'gplink', 'CanonicalName'
# Filter = "(objectClass -eq 'organizationalUnit' -or objectClass -eq 'domainDNS' -or objectClass -eq 'site')"
# Filter = "(objectClass -eq 'organizationalUnit' -or objectClass -eq 'domainDNS' -or objectClass -eq 'site')"
Server = $ForestInformation['QueryServers'][$Domain]['HostName'][0]
}
if ($Linked -contains 'DomainControllers') {
@@ -103,7 +103,7 @@
if ($Linked -contains 'Other') {
$SearchBase = $ForestInformation['DomainsExtended'][$Domain]['DistinguishedName']
#if ($SearchBase -notlike "*$DomainDistinguishedName") {
# we check if SearchBase is part of domain distinugishname. If it isn't we skip
# we check if SearchBase is part of domain distinugishname. If it isn't we skip
# continue
#}
$Splat['Filter'] = "(objectClass -eq 'organizationalUnit')"
@@ -125,6 +125,7 @@
Filter = $Filter
Properties = 'distinguishedName', 'gplink', 'CanonicalName'
Server = $ForestInformation['QueryServers'][$Domain]['HostName'][0]
}
if ($PSBoundParameters.ContainsKey('SearchBase')) {
$DomainDistinguishedName = $ForestInformation['DomainsExtended'][$Domain]['DistinguishedName']
@@ -139,8 +140,12 @@
$Splat['SearchScope'] = $SearchScope
}
Get-ADObject @Splat | ForEach-Object {
Get-PrivGPOZaurrLink -Object $_ -Limited:$Limited.IsPresent -GPOCache $GPOCache
try {
Get-ADObject @Splat | ForEach-Object {
Get-PrivGPOZaurrLink -Object $_ -Limited:$Limited.IsPresent -GPOCache $GPOCache
}
} catch {
Write-Warning "Get-GPOZaurrLink - Processing error $($_.Exception.Message)"
}
}
}
+10 -8
View File
@@ -30,17 +30,17 @@
} elseif ($GPOGuid) {
$getGPOZaurrADSplat['GPOGUID'] = $GPOGuid
}
Get-GPOZaurrAD @getGPOZaurrADSplat | ForEach-Object -Process {
$Objects = Get-GPOZaurrAD @getGPOZaurrADSplat
foreach ($_ in $Objects) {
Write-Verbose "Get-GPOZaurrOwner - Processing GPO: $($_.DisplayName) from domain: $($_.DomainName)"
$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
DisplayName = $_.DisplayName
DomainName = $_.DomainName
GUID = $_.GUID
Owner = $ACL.OwnerName
OwnerSid = $ACL.OwnerSid
OwnerType = $ACL.OwnerType
}
if ($IncludeSysvol) {
$FileOwner = Get-FileOwner -JustPath -Path $_.Path -Resolve
@@ -48,7 +48,9 @@
$Object['SysvolSid'] = $FileOwner.OwnerSid
$Object['SysvolType'] = $FileOwner.OwnerType
$Object['SysvolPath'] = $_.Path
$Object['IsOwnerConsistent'] = if ($ACL.OwnerName -eq $FileOwner.OwnerName) { $true } else { $false }
}
$Object['DistinguishedName'] = $_.GPODistinguishedName
[PSCUstomObject] $Object
}
}
+35 -127
View File
@@ -9,7 +9,7 @@
[alias('Domain', 'Domains')][string[]] $IncludeDomains,
[System.Collections.IDictionary] $ExtendedForestInformation,
[switch] $IncludeGPOObject,
[switch] $VerifyInside
[switch] $VerifyInheritance
)
Begin {
$ForestInformation = Get-WinADForestDetails -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation
@@ -49,7 +49,7 @@
$IsConsistent = 'Not available.'
}
$SysVolpath = -join ('\\', $Domain, '\sysvol\', $Domain, '\Policies\{', $_.ID.GUID, '}')
if ($VerifyInside) {
if ($VerifyInheritance) {
$FolderPermissions = Get-WinADSharePermission -Path $SysVolpath
[Array] $NotInheritedPermissions = foreach ($File in $FolderPermissions) {
if ($File.Path -ne $SysVolpath -and $File.IsInherited -eq $false) {
@@ -65,147 +65,55 @@
$ACLConsistentInside = $null
}
$Object = [ordered] @{
DisplayName = $_.DisplayName # : New Group Policy Object
DomainName = $_.DomainName # : ad.evotec.xyz
ACLConsistent = $IsConsistent
ACLConsistentInside = $ACLConsistentInside
Owner = $_.Owner # : EVOTEC\Enterprise Admins
Path = $_.Path
SysVolPath = $SysvolPath
Id = $_.Id # : 8a7bc515-d7fd-4d1f-90b8-e47c15f89295
GpoStatus = $_.GpoStatus # : AllSettingsEnabled
Description = $_.Description # :
CreationTime = $_.CreationTime # : 04.03.2020 17:19:42
ModificationTime = $_.ModificationTime# : 06.05.2020 10:30:36
UserVersion = $_.UserVersion # : AD Version: 0, SysVol Version: 0
ComputerVersion = $_.ComputerVersion # : AD Version: 1, SysVol Version: 1
WmiFilter = $_.WmiFilter # :
Error = $ErrorMessage
DisplayName = $_.DisplayName # : New Group Policy Object
DomainName = $_.DomainName # : ad.evotec.xyz
ACLConsistent = $IsConsistent
}
if ($VerifyInheritance) {
$Object['ACLConsistentInside'] = $ACLConsistentInside
}
$Object['Owner'] = $_.Owner # : EVOTEC\Enterprise Admins
$Object['Path'] = $_.Path
$Object['SysVolPath '] = $SysvolPath
$Object['Id '] = $_.Id # : 8a7bc515-d7fd-4d1f-90b8-e47c15f89295
$Object['GpoStatus'] = $_.GpoStatus # : AllSettingsEnabled
$Object['Description'] = $_.Description # :
$Object['CreationTime'] = $_.CreationTime # : 04.03.2020 17:19:42
$Object['ModificationTime'] = $_.ModificationTime# : 06.05.2020 10:30:36
$Object['UserVersion'] = $_.UserVersion # : AD Version: 0, SysVol Version: 0
$Object['ComputerVersion'] = $_.ComputerVersion # : AD Version: 1, SysVol Version: 1
$Object['WmiFilter'] = $_.WmiFilter # :
$Object['Error'] = $ErrorMessage
if ($IncludeGPOObject) {
$Object['IncludeGPOObject'] = $_
}
if ($VerifyInside) {
if ($VerifyInheritance) {
$Object['ACLConsistentInsideDetails'] = $NotInheritedPermissions
}
[PSCustomObject] $Object
}
<#
} elseif ($GPOGuid) {
Get-GPO -Guid $GPOGuid -Domain $Domain -Server $QueryServer -ErrorAction SilentlyContinue | ForEach-Object -Process {
try {
$IsConsistent = $_.IsAclConsistent()
$ErrorMessage = ''
} catch {
$ErrorMessage = $_.Exception.Message
Write-Warning "Get-GPOZaurrPermissionConsistency - Failed to get consistency: $($_.Exception.Message)."
$IsConsistent = 'Not available.'
}
$SysVolpath = -join ('\\', $Domain, '\sysvol\', $Domain, '\Policies\{', $_.ID.GUID, '}')
if ($Advanced) {
$FolderPermissions = Get-WinADSharePermission -Path $SysVolpath
[Array] $NotInheritedPermissions = foreach ($File in $FolderPermissions) {
if ($File.Path -ne $SysVolpath -and $File.IsInherited -eq $false) {
$File
}
}
if ($NotInheritedPermissions.Count -eq 0) {
$ACLConsistentInside = $true
} else {
$ACLConsistentInside = $false
if ($Type -eq 'All') {
[PSCustomObject] $Object
} elseif ($Type -eq 'Inconsistent') {
if ($VerifyInheritance) {
if (-not $IsConsistent -or -not $ACLConsistentInside) {
[PSCustomObject] $Object
}
} else {
$ACLConsistentInside = $null
}
$Object = [ordered] @{
DisplayName = $_.DisplayName # : New Group Policy Object
DomainName = $_.DomainName # : ad.evotec.xyz
ACLConsistent = $IsConsistent
ACLConsistentInside = $ACLConsistentInside
Owner = $_.Owner # : EVOTEC\Enterprise Admins
Path = $_.Path
SysVolPath = $SysvolPath
Id = $_.Id # : 8a7bc515-d7fd-4d1f-90b8-e47c15f89295
GpoStatus = $_.GpoStatus # : AllSettingsEnabled
Description = $_.Description # :
CreationTime = $_.CreationTime # : 04.03.2020 17:19:42
ModificationTime = $_.ModificationTime# : 06.05.2020 10:30:36
UserVersion = $_.UserVersion # : AD Version: 0, SysVol Version: 0
ComputerVersion = $_.ComputerVersion # : AD Version: 1, SysVol Version: 1
WmiFilter = $_.WmiFilter # :
Error = $ErrorMessage
}
if ($Advanced) {
$Object['ACLConsistentInsideDetails'] = $NotInheritedPermissions
}
if ($IncludeGPOObject) {
$Object['IncludeGPOObject'] = $_
}
[PSCustomObject] $Object
}
} else {
Get-GPO -All -Domain $Domain -Server $QueryServer | ForEach-Object -Process {
try {
$IsConsistent = $_.IsAclConsistent()
$ErrorMessage = ''
} catch {
$ErrorMessage = $_.Exception.Message
Write-Warning "Get-GPOZaurrPermissionConsistency - Failed to get consistency: $($_.Exception.Message)."
$IsConsistent = 'Not available.'
}
if ($Type -eq 'Consistent') {
if (-not $IsConsistent) {
return
}
} elseif ($Type -eq 'Inconsistent') {
if ($IsConsistent -eq $true) {
return
[PSCustomObject] $Object
}
}
$SysVolpath = -join ('\\', $Domain, '\sysvol\', $Domain, '\Policies\{', $_.ID.GUID, '}')
if ($Advanced) {
$FolderPermissions = Get-WinADSharePermission -Path $SysVolpath
[Array] $NotInheritedPermissions = foreach ($File in $FolderPermissions) {
if ($File.Path -ne $SysVolpath -and $File.IsInherited -eq $false) {
$File
}
}
if ($NotInheritedPermissions.Count -eq 0) {
$ACLConsistentInside = $true
} else {
$ACLConsistentInside = $false
} elseif ($Type -eq 'Consistent') {
if ($VerifyInheritance) {
if ($IsConsistent -and $ACLConsistentInside) {
[PSCustomObject] $Object
}
} else {
$ACLConsistentInside = $null
if ($IsConsistent) {
[PSCustomObject] $Object
}
}
$Object = [ordered] @{
DisplayName = $_.DisplayName # : New Group Policy Object
DomainName = $_.DomainName # : ad.evotec.xyz
ACLConsistent = $IsConsistent
ACLConsistentInside = $ACLConsistentInside
Owner = $_.Owner # : EVOTEC\Enterprise Admins
Path = $_.Path
SysVolPath = $SysvolPath
Id = $_.Id # : 8a7bc515-d7fd-4d1f-90b8-e47c15f89295
GpoStatus = $_.GpoStatus # : AllSettingsEnabled
Description = $_.Description # :
CreationTime = $_.CreationTime # : 04.03.2020 17:19:42
ModificationTime = $_.ModificationTime# : 06.05.2020 10:30:36
UserVersion = $_.UserVersion # : AD Version: 0, SysVol Version: 0
ComputerVersion = $_.ComputerVersion # : AD Version: 1, SysVol Version: 1
WmiFilter = $_.WmiFilter # :
Error = $ErrorMessage
}
if ($Advanced) {
$Object['ACLConsistentInsideDetails'] = $NotInheritedPermissions
}
if ($IncludeGPOObject) {
$Object['IncludeGPOObject'] = $_
}
[PSCustomObject] $Object
}
}
#>
}
}
End {
+37
View File
@@ -0,0 +1,37 @@
function Get-GPOZaurrSysvol {
[cmdletBinding()]
param(
[alias('ForestName')][string] $Forest,
[string[]] $ExcludeDomains,
[string[]] $ExcludeDomainControllers,
[alias('Domain', 'Domains')][string[]] $IncludeDomains,
[alias('DomainControllers')][string[]] $IncludeDomainControllers,
[switch] $SkipRODC,
[Array] $GPOs,
[System.Collections.IDictionary] $ExtendedForestInformation,
[switch] $VerifyDomainControllers
)
$ForestInformation = Get-WinADForestDetails -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExcludeDomainControllers $ExcludeDomainControllers -IncludeDomainControllers $IncludeDomainControllers -SkipRODC:$SkipRODC -ExtendedForestInformation $ExtendedForestInformation
foreach ($Domain in $ForestInformation.Domains) {
Write-Verbose "Get-WinADGPOSysvolFolders - Processing $Domain"
$QueryServer = $ForestInformation['QueryServers']["$Domain"].HostName[0]
Try {
[Array]$GPOs = Get-GPO -All -Domain $Domain -Server $QueryServer
} catch {
Write-Warning "Get-GPOZaurrSysvol - Couldn't get GPOs from $Domain. Error: $($_.Exception.Message)"
continue
}
if ($GPOs.Count -ge 2) {
if (-not $VerifyDomainControllers) {
Test-SysVolFolders -GPOs $GPOs -Server $Domain -Domain $Domain
} else {
foreach ($Server in $ForestInformation['DomainDomainControllers']["$Domain"]) {
Write-Verbose "Get-GPOZaurrSysvol - Processing $Domain \ $($Server.HostName.Trim())"
Test-SysVolFolders -GPOs $GPOs -Server $Server.Hostname -Domain $Domain
}
}
} else {
Write-Warning "Get-GPOZaurrSysvol - GPO count for $Domain is less then 2. This is not expected for fully functioning domain. Skipping processing SYSVOL folder."
}
}
}
+56 -65
View File
@@ -1,4 +1,11 @@
function Get-GPOZaurrWMI {
function Get-WMIFilter {
param(
)
}
function Get-GPOZaurrWMI {
[cmdletBinding()]
Param(
[Guid[]] $Guid,
@@ -13,79 +20,63 @@
$ForestInformation = Get-WinADForestDetails -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation
foreach ($Domain in $ForestInformation.Domains) {
$QueryServer = $ForestInformation['QueryServers'][$Domain]['HostName'][0]
if ($Guid -or $Name) {
foreach ($N in $Name) {
try {
$ldapFilter = "(&(objectClass=msWMI-Som)(msWMI-Name=$N))"
Get-ADObject -LDAPFilter $ldapFilter -Properties $wmiFilterAttr -Server $QueryServer | ForEach-Object -Process {
$WMI = $_.'msWMI-Parm2' -split ';'
[PSCustomObject] @{
DisplayName = $_.'msWMI-Name'
Description = $_.'msWMI-Parm1'
DomainName = $Domain
NameSpace = $WMI[5]
Query = $WMI[6]
Author = $_.'msWMI-Author'
ID = $_.'msWMI-ID'
Created = $_.Created
Modified = $_.Modified
ObjectGUID = $_.'ObjectGUID'
CanonicalName = $_.CanonicalName
DistinguishedName = $_.'DistinguishedName'
}
$Objects = @(
if ($Name) {
foreach ($N in $Name) {
try {
$ldapFilter = "(&(objectClass=msWMI-Som)(msWMI-Name=$N))"
Get-ADObject -LDAPFilter $ldapFilter -Properties $wmiFilterAttr -Server $QueryServer
} catch {
Write-Warning "Get-GPOZaurrWMI - Error processing WMI for $Domain`: $($_.Error.Exception)"
}
}
} elseif ($GUID) {
foreach ($G in $GUID) {
try {
$ldapFilter = "(&(objectClass=msWMI-Som)(Name={$G}))"
Get-ADObject -LDAPFilter $ldapFilter -Properties $wmiFilterAttr -Server $QueryServer
} catch {
Write-Warning "Get-GPOZaurrWMI - Error processing WMI for $Domain`: $($_.Error.Exception)"
}
}
} else {
try {
$ldapFilter = "(objectClass=msWMI-Som)"
Get-ADObject -LDAPFilter $ldapFilter -Properties $wmiFilterAttr -Server $QueryServer
} catch {
Write-Warning "Get-GPOZaurrWMI - Error processing WMI for $Domain`: $($_.Error.Exception)"
}
}
foreach ($G in $GUID) {
$ldapFilter = "(&(objectClass=msWMI-Som)(Name={$G}))"
try {
Get-ADObject -LDAPFilter $ldapFilter -Properties $wmiFilterAttr -Server $QueryServer | ForEach-Object -Process {
$WMI = $_.'msWMI-Parm2' -split ';'
[PSCustomObject] @{
DisplayName = $_.'msWMI-Name'
Description = $_.'msWMI-Parm1'
DomainName = $Domain
NameSpace = $WMI[5]
Query = $WMI[6]
Author = $_.'msWMI-Author'
ID = $_.'msWMI-ID'
Created = $_.Created
Modified = $_.Modified
ObjectGUID = $_.'ObjectGUID'
CanonicalName = $_.CanonicalName
DistinguishedName = $_.'DistinguishedName'
}
}
} catch {
Write-Warning "Get-GPOZaurrWMI - Error processing WMI for $Domain`: $($_.Error.Exception)"
)
foreach ($_ in $Objects) {
$WMI = $_.'msWMI-Parm2' -split ';' #$WMI = $_.'msWMI-Parm2'.Split(';',8)
[Array] $Data = for ($i = 0; $i -lt $WMI.length; $i += 6) {
if ($WMI[$i + 5]) {
#[PSCustomObject] @{
# NameSpace = $WMI[$i + 5]
# Query = $WMI[$i + 6]
#}
-join ($WMI[$i + 5], ';' , $WMI[$i + 6])
}
}
} else {
$ldapFilter = "(objectClass=msWMI-Som)"
try {
Get-ADObject -LDAPFilter $ldapFilter -Properties $wmiFilterAttr -Server $QueryServer | ForEach-Object -Process {
$WMI = $_.'msWMI-Parm2' -split ';'
[PSCustomObject] @{
DisplayName = $_.'msWMI-Name'
Description = $_.'msWMI-Parm1'
DomainName = $Domain
NameSpace = $WMI[5]
Query = $WMI[6]
Author = $_.'msWMI-Author'
ID = $_.'msWMI-ID'
Created = $_.Created
Modified = $_.Modified
ObjectGUID = $_.'ObjectGUID'
CanonicalName = $_.CanonicalName
DistinguishedName = $_.'DistinguishedName'
}
}
} catch {
Write-Warning "Get-GPOZaurrWMI - Error processing WMI for $Domain`: $($_.Error.Exception)"
[PSCustomObject] @{
DisplayName = $_.'msWMI-Name'
Description = $_.'msWMI-Parm1'
DomainName = $Domain
#NameSpace = $WMI[$i + 5]
#Query = $WMI[$i + 6]
QueryCount = $Data.Count
Query = $Data -join ","
Author = $_.'msWMI-Author'
ID = $_.'msWMI-ID'
Created = $_.Created
Modified = $_.Modified
ObjectGUID = $_.'ObjectGUID'
CanonicalName = $_.CanonicalName
DistinguishedName = $_.'DistinguishedName'
}
}
}
}
<#
+3 -2
View File
@@ -3,6 +3,7 @@
param(
[parameter(Mandatory)][string] $Name,
[string] $Description = ' ',
[string] $Namespace = 'root\CIMv2',
[parameter(Mandatory)][string] $Query,
[switch] $SkipQueryCheck,
[switch] $Force,
@@ -50,7 +51,7 @@
[Array] $ExistingWmiFilter = Get-GPOZaurrWMI -ExtendedForestInformation $ForestInformation -IncludeDomains $Domain -Name $Name
if ($ExistingWmiFilter.Count -eq 0) {
[string] $WMIParm2 = -join ("1;3;10;", $Query.Length.ToString(), ";WQL;root\CIMv2;", $Query , ";")
[string] $WMIParm2 = -join ("1;3;10;", $Query.Length.ToString(), ";WQL;$Namespace;", $Query , ";")
$OtherAttributes = @{
"msWMI-Name" = $Name
"msWMI-Parm1" = $Description
@@ -67,7 +68,7 @@
try {
Write-Verbose "New-GPOZaurrWMI - Creating WMI filter $Name in $Domain"
New-ADObject -name $GUID -type "msWMI-Som" -Path $WMIPath -OtherAttributes $OtherAttributes -Server $QueryServer
New-ADObject -Name $GUID -Type "msWMI-Som" -Path $WMIPath -OtherAttributes $OtherAttributes -Server $QueryServer
} catch {
Write-Warning "New-GPOZaurrWMI - Creating GPO filter error $($_.Exception.Message). Terminating."
return
@@ -0,0 +1,13 @@
function Remove-GPOZaurrOrphanedSysvolFolders {
[cmdletBinding(SupportsShouldProcess)]
param(
[int] $LimitProcessing = [int32]::MaxValue
)
Get-GPOZaurrSysvol | Where-Object {
if ($_.Status -eq 'Orphaned GPO') {
$_
}
} | Select-Object | Select-Object -First $LimitProcessing | ForEach-Object {
Remove-Item -Recurse -Force -LiteralPath $_.Path
}
}
+1 -1
View File
@@ -27,7 +27,7 @@
Begin {
$Count = 0
$ForestInformation = Get-WinADForestDetails -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation
$ADAdministrativeGroups = Get-ADADministrativeGroups -Type DomainAdmins, EnterpriseAdmins -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation
$ADAdministrativeGroups = Get-ADADministrativeGroups -Type DomainAdmins, EnterpriseAdmins -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ForestInformation
if ($Type -eq 'Unknown') {
if ($SkipAdministrative -or $SkipWellKnown) {
Write-Warning "Remove-GPOZaurrPermission - Using SkipAdministrative or SkipWellKnown while looking for Unknown doesn't make sense as only Unknown will be displayed."
-113
View File
@@ -120,24 +120,6 @@
$_
}
}
<#
if (-not $AdministrativeGroup -and (-not $AdministrativeGroupSysvol -and -not $SkipSysvol)) {
$Action = 'Both'
$_
} elseif (-not $AdministrativeGroup) {
$Action = 'OnlyGPO'
$_
} elseif (-not $AdministrativeGroupSysvol -and -not $SkipSysvol) {
$Action = 'OnlyFileSystem'
$_
} else {
if ($_.Owner -ne $_.SysvolOwner) {
$Action = 'OnlyFileSystem'
$_
}
}
#>
} elseif ($Type -eq 'Unknown') {
if (-not $_.Owner -or (-not $_.SysvolOwner -and -not $SkipSysvol)) {
$_
@@ -172,9 +154,6 @@
}
} | Select-Object -First $LimitProcessing | ForEach-Object -Process {
$GPO = $_
#if (-not $Principal) {
# $Principal = $ADAdministrativeGroups["$($GPO.DomainName)"]['DomainAdmins']
#}
if (-not $Principal) {
$DefaultPrincipal = $ADAdministrativeGroups["$($_.DomainName)"]['DomainAdmins']
} else {
@@ -197,98 +176,6 @@
}
}
}
<#
if ($Type -contains 'All') {
# Regardless who is the owner it is overwritten
if ($Principal) {
Write-Verbose "Set-GPOZaurrOwner - Changing GPO: $($GPO.DisplayName) from domain: $($GPO.DomainName) from owner $($GPO.Owner)/$($GPO.OwnerSID) to $Principal"
Set-ADACLOwner -ADObject $GPO.GPODistinguishedName -Principal $Principal -Verbose:$false -WhatIf:$WhatIfPreference
} else {
$DefaultPrincipal = $ADAdministrativeGroups["$($GPO.DomainName)"]['DomainAdmins']
Write-Verbose "Set-GPOZaurrOwner - Changing GPO: $($GPO.DisplayName) from domain: $($GPO.DomainName) from owner $($GPO.Owner)/$($GPO.OwnerSID) to $DefaultPrincipal"
Set-ADACLOwner -ADObject $GPO.GPODistinguishedName -Principal $DefaultPrincipal -Verbose:$false -WhatIf:$WhatIfPreference
}
$Count++
if ($Count -eq $LimitProcessing) {
break
}
} elseif ($Type -contains 'NotAdministrative' -and $Type -notcontains 'All') {
if ($GPO.Owner) {
$AdministrativeGroup = $ADAdministrativeGroups['ByNetBIOS']["$($GPO.Owner)"]
if (-not $AdministrativeGroup) {
if ($Principal) {
Write-Verbose "Set-GPOZaurrOwner - Changing GPO: $($GPO.DisplayName) from domain: $($GPO.DomainName) from owner $($GPO.Owner)/$($GPO.OwnerSID) to $Principal"
Set-ADACLOwner -ADObject $GPO.GPODistinguishedName -Principal $DefaultPrincipal -Verbose:$false -WhatIf:$WhatIfPreference
} else {
$DefaultPrincipal = $ADAdministrativeGroups["$($GPO.DomainName)"]['DomainAdmins']
Write-Verbose "Set-GPOZaurrOwner - Changing GPO: $($GPO.DisplayName) from domain: $($GPO.DomainName) from owner $($GPO.Owner)/$($GPO.OwnerSID) to $DefaultPrincipal"
Set-ADACLOwner -ADObject $GPO.GPODistinguishedName -Principal $DefaultPrincipal -Verbose:$false -WhatIf:$WhatIfPreference
}
$Count++
if ($Count -eq $LimitProcessing) {
return
}
}
}
} else ($Type -contains 'Unknown' -and $Type -notcontains 'All') {
if ($null -eq $GPO.Owner) {
if ($Principal) {
Write-Verbose "Set-GPOZaurrOwner - Changing GPO: $($GPO.DisplayName) from domain: $($GPO.DomainName) from owner NULL/$($GPO.OwnerSID) to $Principal"
Set-ADACLOwner -ADObject $GPO.GPODistinguishedName -Principal $Principal -Verbose:$false -WhatIf:$WhatIfPreference
} else {
$DefaultPrincipal = $ADAdministrativeGroups["$($GPO.DomainName)"]['DomainAdmins']
Write-Verbose "Set-GPOZaurrOwner - Changing GPO: $($GPO.DisplayName) from domain: $($GPO.DomainName) from owner NULL/$($GPO.OwnerSID) to $DefaultPrincipal"
Set-ADACLOwner -ADObject $GPO.GPODistinguishedName -Principal $DefaultPrincipal -Verbose:$false -WhatIf:$WhatIfPreference
}
$Count++
if ($Count -eq $LimitProcessing) {
break
}
}
} else {
$GPO = $_
if ($Principal) {
Write-Verbose "Set-GPOZaurrOwner - Changing GPO: $($GPO.DisplayName) from domain: $($GPO.DomainName) from owner $($GPO.Owner)/$($GPO.OwnerSID) to $Principal"
Set-ADACLOwner -ADObject $GPO.GPODistinguishedName -Principal $Principal -Verbose:$false -WhatIf:$WhatIfPreference
} else {
$DefaultPrincipal = $ADAdministrativeGroups["$($GPO.DomainName)"]['DomainAdmins']
Write-Verbose "Set-GPOZaurrOwner - Changing GPO: $($GPO.DisplayName) from domain: $($GPO.DomainName) from owner $($GPO.Owner)/$($GPO.OwnerSID) to $DefaultPrincipal"
Set-ADACLOwner -ADObject $GPO.GPODistinguishedName -Principal $DefaultPrincipal -Verbose:$false -WhatIf:$WhatIfPreference
}
}
#>
#}
#>
#}
<#
else {
$getGPOZaurrOwnerSplat = @{
IncludeSysvol = $IncludeSysVol
Forest = $Forest
IncludeDomains = $IncludeDomains
ExcludeDomains = $ExcludeDomains
ExtendedForestInformation = $ExtendedForestInformation
ADAdministrativeGroups = $ADAdministrativeGroups
GPOName = $GPOName
GPOGuid = $GPOGUiD
}
Get-GPOZaurrOwner @getGPOZaurrOwnerSplat $IncludeSysVol | ForEach-Object -Process {
$GPO = $_
if ($Principal) {
Write-Verbose "Set-GPOZaurrOwner - Changing GPO: $($GPO.DisplayName) from domain: $($GPO.DomainName) from owner $($GPO.Owner)/$($GPO.OwnerSID) to $Principal"
Set-ADACLOwner -ADObject $GPO.GPODistinguishedName -Principal $Principal -Verbose:$false -WhatIf:$WhatIfPreference
} else {
$DefaultPrincipal = $ADAdministrativeGroups["$($GPO.DomainName)"]['DomainAdmins']
Write-Verbose "Set-GPOZaurrOwner - Changing GPO: $($GPO.DisplayName) from domain: $($GPO.DomainName) from owner $($GPO.Owner)/$($GPO.OwnerSID) to $DefaultPrincipal"
Set-ADACLOwner -ADObject $GPO.GPODistinguishedName -Principal $DefaultPrincipal -Verbose:$false -WhatIf:$WhatIfPreference
}
$Count++
if ($Count -eq $LimitProcessing) {
break
}
}
}
#>
}
End {