Skip to content

Commit

Permalink
tidy up code and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsweetman committed Mar 15, 2024
1 parent 749cc25 commit ea1ba03
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 60 deletions.
73 changes: 16 additions & 57 deletions powershell/Modules/ModPlatformAD/ModPlatformADOU.psm1
Original file line number Diff line number Diff line change
@@ -1,59 +1,19 @@
# function New-ADOrganizationalUnit {

# <#
# .SYNOPSIS
# Creates a New-ADOrganizationalUnit

# .DESCRIPTION
# Using configuration returned from Get-ModPlatformADConfig, this function
# optionally assumes a role to access a secret containing the password of the
# domain join username. EC2 requires permissions to join the given role,
# a SSM parameter containing account IDs, and the aws cli.

# .PARAMETER Name
# Name of the Organizational Unit to create

# .PARAMETER Path
# The path of the Organizational Unit to create

# .PARAMETER Description
# Description of the Organizational Unit to create

# .PARAMETER ProtectedFromAccidentalDeletion
# Whether the Organizational Unit should be protected from accidental deletion, defaults to false

# .EXAMPLE
# New-ADOrganizationalUnit -Name "TestOU" -Path "OU=Test,DC=example,DC=com" -Description "Test OU"

# .OUTPUTS
# OU folder created
# #>

# [CmdletBinding()]
# param (
# [Parameter(Mandatory = $true)]
# [string]$Name,

# [Parameter(Mandatory = $true)]
# [string]$Path,

# [Parameter(Mandatory = $false)]
# [string]$Description,

# [Parameter(Mandatory = $false)]
# [bool]$ProtectedFromAccidentalDeletion = $false
# )

# $ou = Get-ADOrganizationalUnit -Filter "Name -eq '$Name'" -SearchBase $Path
# if ($ou) {
# Write-Host "Organizational Unit $Name already exists in $Path" -ForegroundColor Yellow
# } else {
# $ou = New-ADOrganizationalUnit -Name $Name -Path $Path -Description $Description -ProtectedFromAccidentalDeletion $ProtectedFromAccidentalDeletion
# Write-Host "Organizational Unit $Name created in $Path" -ForegroundColor Green
# }
# }

function Set-OUsAndApplyGPOs {
<#
.SYNOPSIS
Recursively creates Organizational Units (OUs) and applies Group Policy Objects (GPOs) to the given domain
.DESCRIPTION
Recursively creates Organizational Units (OUs) and applies Group Policy Objects (GPOs) to the given domain
.PARAMETER Ou
The OU to create
.PARAMETER Path
The path of the OU to create
.PARAMETER ProtectedFromAccidentalDeletion
Whether the OU should be protected from accidental deletion, defaults to false
In production environments, it is recommended to set this to true
.OUTPUTS
OU folder created
#>
param (
[Parameter(Mandatory=$true)]
[psobject]$Ou,
Expand Down Expand Up @@ -87,5 +47,4 @@ function Set-OUsAndApplyGPOs {
}
}

# Export-ModuleMember -Function New-ADOrganizationalUnit
Export-ModuleMember -Function Set-OUsAndApplyGPOs
# Export-ModuleMember -Function Set-OUsAndApplyGPOs
1 change: 1 addition & 0 deletions powershell/Scripts/ModPlatformAD/New-ModPlatformGPO.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
./New-ModPlatformGPO.ps1 -DomainNameFQDN "test.loc" -ConfigFilePath "config.yaml"
.OUTPUTS
Check Group Policy Management tools on the server to see the GPOs created
#>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#
.SYNOPSIS
Retrieve appropriate AD config for the given Modernisation Platform environment.
Applies the OU and GPO structure to the given domain based on a yaml config file.
.DESCRIPTION
Either pass in the domain name as a parameter, or derive the AD configuration
Expand All @@ -10,10 +10,14 @@
.PARAMETER DomainNameFQDN
Specify the FQDN of the domain name to join
.PARAMETER ConfigFilePath
Path to the yaml definition of the OU/GPO structure. See ../../Configs/ADConfigDevTest.yaml for example
.EXAMPLE
$ADConfig = Get-ModPlatformADConfig
./Set-ModPlatformADOUStructure.ps1 -DomainNameFQDN "test.loc" -ConfigFilePath "../../Configs/ADConfigDevTest.yaml"
.OUTPUTS
.NOTES
GPO's referenced in the script have to have been created FIRST before running this, otherwise GPO's will not be applied
#>

Expand Down

0 comments on commit ea1ba03

Please sign in to comment.