How can I populate "OtherAttributes" via a csv file?
This script works fine except for populating extensionAttribute2. The information to be populated into extensionAttribute2 will not always be the same, so I need to be able to enter that information into the csv file. The script populates extensionAttribute2 with $item.extensionAttribute2, instead of what is entered in the csv file "True".
PoSH Script:
Import-Module ActiveDirectory
$csv = @()
$csv = Import-CSV -Path "C:\Temp\Buld-AD-Group-Creation.csv"
#Get Domain Base
$searchbase = Get-ADDomain | ForEach { $_.DistinguishedName }
ForEach ($Item in $csv)
$check = [ADSI]::Exists("LDAP://$($item.GroupLocation),$($searchbase)")
If ($check -eq $True)
{
Try
$exists = Get-ADGroup $item.GroupName
Write-Host "Group $($item.GroupName) already exists! Group creation skipped!"
}
Catch
{
$Create = New-ADGroup -Name $item.GroupName -GroupScope $item.GroupType -Path ($($item.GroupLocation)+","+$($searchbase)) -description $item.description -managedBy $item.managedBy -OtherAttributes @{"Info" = 'Auto-Provisioned'; "extensionAttribute2" = '$item.extensionAttribute2' }
Write-Host "Group $($item.GroupName) created!"
}
}
Else
{
Write-Host "Group Not Created!"
}
}
CSV Input File:
GroupName,GroupType,GroupLocation,Description,ManagedBy,extensionAttribute2
Tst_PS_Grp1,Global,"MY OU Name","This is a new group",AccountName,"True"
mamadukes