Packer.Images/scripts/ADDS/payload/scripts/02.Groups.ps1

25 lines
915 B
PowerShell
Raw Normal View History

#Requires -Modules 'ActiveDirectory'
Param(
[Parameter(Mandatory)]
[hashtable]$Parameter
)
# Only executed on primary Domain Controller
If ((Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole -eq 5) {
$GetContentSplat = @{
Path = "$($PSScriptRoot)\$($MyInvocation.MyCommand)".Replace('.ps1', ".csv")
}
$CSVImport = (Get-Content @GetContentSplat) | ConvertFrom-Csv
ForEach ($Group in $CSVImport) {
$NewADGroupSplat = @{
Name = ($Group.DistinguishedName -split ',', 2)[0].Substring(3)
Path = ($Group.DistinguishedName -split ',', 2)[1] + ',DC=' + $Parameter['addsconfig.domainname'].Replace('.', ',DC=')
Description = $Group.Description
GroupCategory = 'Security'
GroupScope = 'Global'
ErrorAction = 'SilentlyContinue'
}
New-ADGroup @NewADGroupSplat
}
}