forked from blockchainhelp-eu/poweshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AD-GPO-Get-ADGPOReplication.ps1
98 lines (95 loc) · 3.41 KB
/
AD-GPO-Get-ADGPOReplication.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function Get-ADGPOReplication
{
<#
.SYNOPSIS
This function retrieve one or all the GPO and report their DSVersions and SysVolVersions (Users and Computers)
.DESCRIPTION
This function retrieve one or all the GPO and report their DSVersions and SysVolVersions (Users and Computers)
.PARAMETER GPOName
Specify the name of the GPO
.PARAMETER All
Specify that you want to retrieve all the GPO (slow if you have a lot of Domain Controllers)
.EXAMPLE
Get-ADGPOReplication -GPOName "Default Domain Policy"
.EXAMPLE
Get-ADGPOReplication -All
.NOTES
Francois-Xavier Cat
@lazywinadm
lazywinadmin.com
VERSION HISTORY
1.0 2014.09.22 Initial version
Adding some more Error Handling
Fix some typo
#>
#requires -version 3
[CmdletBinding()]
PARAM (
[parameter(Mandatory = $True, ParameterSetName = "One")]
[String[]]$GPOName,
[parameter(Mandatory = $True, ParameterSetName = "All")]
[Switch]$All
)
BEGIN
{
TRY
{
if (-not (Get-Module -Name ActiveDirectory)) { Import-Module -Name ActiveDirectory -ErrorAction Stop -ErrorVariable ErrorBeginIpmoAD }
if (-not (Get-Module -Name GroupPolicy)) { Import-Module -Name GroupPolicy -ErrorAction Stop -ErrorVariable ErrorBeginIpmoGP }
}
CATCH
{
Write-Warning -Message "[BEGIN] Something wrong happened"
IF ($ErrorBeginIpmoAD) { Write-Warning -Message "[BEGIN] Error while Importing the module Active Directory" }
IF ($ErrorBeginIpmoGP) { Write-Warning -Message "[BEGIN] Error while Importing the module Group Policy" }
Write-Warning -Message "[BEGIN] $($Error[0].exception.message)"
}
}
PROCESS
{
FOREACH ($DomainController in ((Get-ADDomainController -ErrorAction Stop -ErrorVariable ErrorProcessGetDC -filter *).hostname))
{
TRY
{
IF ($psBoundParameters['GPOName'])
{
Foreach ($GPOItem in $GPOName)
{
$GPO = Get-GPO -Name $GPOItem -Server $DomainController -ErrorAction Stop -ErrorVariable ErrorProcessGetGPO
[pscustomobject][ordered] @{
GroupPolicyName = $GPOItem
DomainController = $DomainController
UserVersion = $GPO.User.DSVersion
UserSysVolVersion = $GPO.User.SysvolVersion
ComputerVersion = $GPO.Computer.DSVersion
ComputerSysVolVersion = $GPO.Computer.SysvolVersion
}#PSObject
}#Foreach ($GPOItem in $GPOName)
}#IF ($psBoundParameters['GPOName'])
IF ($psBoundParameters['All'])
{
$GPOList = Get-GPO -All -Server $DomainController -ErrorAction Stop -ErrorVariable ErrorProcessGetGPOAll
foreach ($GPO in $GPOList)
{
[pscustomobject][ordered] @{
GroupPolicyName = $GPO.DisplayName
DomainController = $DomainController
UserVersion = $GPO.User.DSVersion
UserSysVolVersion = $GPO.User.SysvolVersion
ComputerVersion = $GPO.Computer.DSVersion
ComputerSysVolVersion = $GPO.Computer.SysvolVersion
}#PSObject
}
}#IF ($psBoundParameters['All'])
}#TRY
CATCH
{
Write-Warning -Message "[PROCESS] Something wrong happened"
IF ($ErrorProcessGetDC) { Write-Warning -Message "[PROCESS] Error while running retrieving Domain Controllers with Get-ADDomainController" }
IF ($ErrorProcessGetGPO) { Write-Warning -Message "[PROCESS] Error while running Get-GPO" }
IF ($ErrorProcessGetGPOAll) { Write-Warning -Message "[PROCESS] Error while running Get-GPO -All" }
Write-Warning -Message "[PROCESS] $($Error[0].exception.message)"
}
}#FOREACH
}#PROCESS
}