Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Set AD group gidNumber for multiple groups

$
0
0

Thanks Dave you are amazing :D
Perfect!
I think I will take a break now :D

Below creates the new groups that are required and then modifies the gidNumber.


$Groups = Import-Csv C:\Scripts\CSVFILE.csv -UseCulture

foreach ($Group in $Groups) {

New-ADGroup -Name $Group.Name -Description $Group.Description -GroupCategory "Security" -GroupScope "Universal" -DisplayName $Group.displayNamePrintable -Path $Group.Path -SamAccountName $Group.SamAccountName -Verbose

}

foreach ($csvEntry in $groups)
{
try
{
$group = Get-ADGroup -Identity $csvEntry.SamAccountName -ErrorAction Stop

$GID = [int]$group.SID.Value.Substring([int]$group.SID.Value.Lastindexof("-")+1)+1000

$group | Set-ADGroup -Replace @{gidNumber=$GID} -Verbose -ErrorAction Stop
}
catch
{
# handle error however you like
}
}

Once again many thanks.
Iain


Viewing all articles
Browse latest Browse all 13067

Trending Articles