Skip to content

Commit 97b063e

Browse files
authored
Merge pull request lazywinadmin#15 from lazywinadmin/dev
Minor updates
2 parents 059f8b3 + eaa517d commit 97b063e

File tree

105 files changed

+4820
-4765
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+4820
-4765
lines changed

AD-FSMO-Get-ADFSMORole/AD-FSMO-Get-ADFSMORole.ps1

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

AD-GROUP-Get-NestedMember/AD-GROUP-Get-NestedMember.ps1

Lines changed: 65 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
Find all Nested members of a group
88
.PARAMETER GroupName
99
Specify one or more GroupName to audit
10+
.PARAMETER RelationShipPath
11+
Show the relation ship path
12+
.PARAMETER MaxDepth
13+
Specify the Max
1014
.Example
1115
Get-NestedMember -GroupName TESTGROUP
1216
@@ -27,80 +31,72 @@
2731
[String]$RelationShipPath,
2832
[Int]$MaxDepth
2933
)
30-
BEGIN
31-
{
32-
$DepthCount = 1
34+
TRY{
35+
$FunctionName = (Get-Variable -Name MyInvocation -Scope 0 -ValueOnly).MyCommand
3336

34-
TRY{
35-
if(-not(Get-Module Activedirectory -ErrorAction Stop)){
36-
Write-Verbose -Message "[BEGIN] Loading ActiveDirectory Module"
37-
Import-Module ActiveDirectory -ErrorAction Stop}
38-
}
39-
CATCH
37+
Write-Verbose -Message "[$FunctionName] Check if ActiveDirectory Module is available"
38+
if(-not(Get-Module Activedirectory -ErrorAction Stop))
4039
{
41-
Write-Warning -Message "[BEGIN] An Error occured"
42-
Write-Warning -Message $error[0].exception.message
40+
Write-Verbose -Message "[$FunctionName] Loading ActiveDirectory Module"
41+
Import-Module ActiveDirectory -ErrorAction Stop
4342
}
44-
}
45-
PROCESS
46-
{
47-
TRY
43+
44+
# Set Depth Counter
45+
$DepthCount = 1
46+
FOREACH ($Group in $GroupName)
4847
{
49-
FOREACH ($Group in $GroupName)
48+
Write-Verbose -Message "[$FunctionName] Group '$Group'"
49+
50+
# Get the Group Information
51+
$GroupObject = Get-ADGroup -Identity $Group -ErrorAction Stop
52+
53+
IF($GroupObject)
5054
{
51-
# Get the Group Information
52-
$GroupObject = Get-ADGroup -Identity $Group -ErrorAction Stop
53-
54-
IF($GroupObject)
55-
{
56-
# Get the Members of the group
57-
$GroupObject | Get-ADGroupMember -ErrorAction Stop | ForEach-Object -Process {
58-
59-
# Get the name of the current group (to reuse in output)
60-
$ParentGroup = $GroupObject.Name
61-
62-
63-
# Avoid circular
64-
IF($RelationShipPath -notlike ".\ $($GroupObject.samaccountname) \*")
65-
{
66-
if($PSBoundParameters["RelationShipPath"]) {
67-
68-
$RelationShipPath = "$RelationShipPath \ $($GroupObject.samaccountname)"
69-
55+
Write-Verbose -Message "[$FunctionName] Group '$Group' - Retrieving members"
56+
57+
# Get the Members of the group
58+
$GroupObject | Get-ADGroupMember -ErrorAction Stop | ForEach-Object -Process {
59+
60+
# Get the name of the current group (to reuse in output)
61+
$ParentGroup = $GroupObject.Name
62+
63+
64+
# Avoid circular
65+
IF($RelationShipPath -notlike ".\ $($GroupObject.samaccountname) \*")
66+
{
67+
if($PSBoundParameters["RelationShipPath"]) {
68+
69+
$RelationShipPath = "$RelationShipPath \ $($GroupObject.samaccountname)"
70+
71+
}
72+
Else{$RelationShipPath = ".\ $($GroupObject.samaccountname)"}
73+
74+
Write-Verbose -Message "[$FunctionName] Group '$Group' - Name:$($_.name) | ObjectClass:$($_.ObjectClass)"
75+
$CurrentObject = $_
76+
switch ($_.ObjectClass)
77+
{
78+
"group" {
79+
# Output Object
80+
$CurrentObject | Select-Object Name,SamAccountName,ObjectClass,DistinguishedName,@{Label="ParentGroup";Expression={$ParentGroup}}, @{Label="RelationShipPath";Expression={$RelationShipPath}}
81+
82+
if (-not($DepthCount -lt $MaxDepth)){
83+
# Find Child
84+
Get-NestedMember -GroupName $CurrentObject.Name -RelationShipPath $RelationShipPath
85+
$DepthCount++
7086
}
71-
Else{$RelationShipPath = ".\ $($GroupObject.samaccountname)"}
72-
73-
Write-Verbose -Message "[PROCESS] Name:$($_.name) | ObjectClass:$($_.ObjectClass)"
74-
$CurrentObject = $_
75-
switch ($_.ObjectClass)
76-
{
77-
"group" {
78-
# Output Object
79-
$CurrentObject | Select-Object Name,SamAccountName,ObjectClass,DistinguishedName,@{Label="ParentGroup";Expression={$ParentGroup}}, @{Label="RelationShipPath";Expression={$RelationShipPath}}
80-
81-
if (-not($DepthCount -lt $MaxDepth)){
82-
# Find Child
83-
Get-NestedMember -GroupName $CurrentObject.Name -RelationShipPath $RelationShipPath
84-
$DepthCount++
85-
}
86-
}#Group
87-
default { $CurrentObject | Select-Object Name,SamAccountName,ObjectClass,DistinguishedName, @{Label="ParentGroup";Expression={$ParentGroup}},@{Label="RelationShipPath";Expression={$RelationShipPath}}}
88-
}#Switch
89-
}#IF($RelationShipPath -notmatch $($GroupObject.samaccountname))
90-
ELSE{Write-Warning -Message "[PROCESS] Circular group membership detected with $($GroupObject.samaccountname)"}
91-
}#ForeachObject
92-
}#IF($GroupObject)
93-
ELSE {
94-
Write-Warning -Message "[PROCESS] Can't find the group $Group"
95-
}#ELSE
96-
}#FOREACH ($Group in $GroupName)
97-
}#TRY
98-
CATCH{
99-
Write-Warning -Message "[PROCESS] An Error occured"
100-
Write-Warning -Message $error[0].exception.message }
101-
}#PROCESS
102-
END
103-
{
104-
Write-Verbose -Message "[END] Get-NestedMember"
87+
}#Group
88+
default { $CurrentObject | Select-Object Name,SamAccountName,ObjectClass,DistinguishedName, @{Label="ParentGroup";Expression={$ParentGroup}},@{Label="RelationShipPath";Expression={$RelationShipPath}}}
89+
}#Switch
90+
}#IF($RelationShipPath -notmatch $($GroupObject.samaccountname))
91+
ELSE {Write-Warning -Message "[$FunctionName] Circular group membership detected with $($GroupObject.samaccountname)"}
92+
}#ForeachObject
93+
}#IF($GroupObject)
94+
ELSE {
95+
Write-Warning -Message "[$FunctionName] Can't find the group $Group"
96+
}#ELSE
97+
}#FOREACH ($Group in $GroupName)
98+
}#TRY
99+
CATCH{
100+
$PSCmdlet.ThrowTerminatingError($_)
105101
}
106102
}

AD-GROUP-Get-ParentGroup/AD-GROUP-Get-ParentGroup.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@
5151
{
5252
# Show a warning if more than 1 object is found
5353
if ($ADObject.count -gt 1){Write-Warning -Message "More than one object found with the $obj request"}
54-
54+
5555
FOREACH ($Account in $ADObject)
5656
{
5757
Write-Verbose -Message "[PROCESS] $($Account.name)"
5858
$Account | Select-Object -ExpandProperty memberof | ForEach-Object -Process {
5959

6060
$CurrentObject = Get-Adobject -LDAPFilter "(|(anr=$_)(distinguishedname=$_))" -Properties Samaccountname
61-
62-
61+
62+
6363
Write-Output $CurrentObject | Select-Object Name,SamAccountName,ObjectClass, @{L="Child";E={$Account.samaccountname}}
64-
64+
6565
Write-Verbose -Message "Inception - $($CurrentObject.distinguishedname)"
6666
Get-ParentGroup -OutBuffer $CurrentObject.distinguishedname
6767

0 commit comments

Comments
 (0)