Everything works great in this script as long as there is an entry for each field in the csv file.
This is the csv file formant:
GroupName,Description,ManagedBy,extensionAttribute2,extensionAttribute3,extensionAttribute4
TstPosh20,REQ#\TASK#,smith,True,cohen,lawrence
TstPosh21,REQ#\TASK#,cohen,True,lawrence,
TstPosh22,REQ#\TASK#lawrence,,,
Issue: If on of the fields does not have an enty, "The server is unwilling to process the request". I've multiple things with no success. One of the things was to incorporate the following the If/Else:
if ($item.extensionAttribute3 -eq ""){
}Else{
Is there a way around this issue using this script of do I have to change this script to include the IF logic?
Import-Module ActiveDirectory
$csv = Import-Csv -Path "C:\Temp\Bulk-NewADGroup.csv"
foreach($Item in $csv){
if(Get-ADGroup -filter 'Name -eq "$($item.GroupName)"'){
Write-Host "$($item.GroupName) already exists at that location! Group creation skipped!" -ForegroundColor Red}
else{
$newgrp=@{
Name=$Item.GroupName
GroupScope =1
Path="OU=Hers,DC=MY,DC=His,DC=org"
Description=$Item.description
ManagedBy=$Item.managedBy
OtherAttributes=@{Info='Auto-Provisioned';extensionAttribute2=$Item.extensionAttribute2;extensionAttribute3=$Item.extensionAttribute3;extensionAttribute4=$Item.extensionAttribute4}
}
Try{
New-ADGroup @newgrp -ErrorAction Stop
Write-Host "Group $($item.GroupName) created!" -ForegroundColor Green
}
Catch{
Write-Host "$_" -ForegroundColor Cyan
}
}
} mamadukes