Not sure what is happening with my script.

<p class=“s14dydj4-10 kiAEUp”>wonderful script to user to Create bulk equipment Resources on Exchange with Set-User attributes and Set-Calendarprocessing attributes. I ti designed to run off of a CSV file i created. I run the script and what seems to happen that only one of the items gets created and it will not parse to the other lines . it stops at an error:</p>
<p class=“s14dydj4-10 kiAEUp”>Active Directory operation failed on SERVER. The object ‘CN=CN,OU=OU ,OU=OU,DC=DC,DC=DC,DC=DC,DC=DC’ already exists.</p>

<p class="s14dydj4-10 kiAEUp">+ CategoryInfo : NotSpecified: (:) [New-Mailbox], ADObjectAlreadyExistsException</p> <p class="s14dydj4-10 kiAEUp">+ FullyQualifiedErrorId : [Server=SERVER,RequestId=whatever ,TimeStamp=4/5/2019 3:50:37 PM] [FailureCategory=Cmdlet-ADObjectAlreadyExistsException] FE3A467A,Microsoft.Exchan</p> <p class="s14dydj4-10 kiAEUp">ge.Management.RecipientTasks.NewMailbox</p> <p class="s14dydj4-10 kiAEUp">+ PSComputerName : SERVER</p>
<p class="s14dydj4-10 kiAEUp">At that point, the script stops and does not continue to the next line.</p> <p class="s14dydj4-10 kiAEUp">I've checked:</p>
  1. <p class="s14dydj4-10 kiAEUp">Script</p>
<p class="s14dydj4-10 kiAEUp">- Debugged to make sure everything was working properly</p> <p class="s14dydj4-10 kiAEUp">2. Csv</p> <p class="s14dydj4-10 kiAEUp">- made are the csv is formatted correctly:</p>
<p class="s14dydj4-10 kiAEUp">Equipmentname,alias,Oupath,Office,TelephoneNumber,Street,City,State,ZIP,Country,Notes</p> <p class="s14dydj4-10 kiAEUp">test2,test2,Mailboxes,3,4,5,6,7,8,United States,10</p> <p class="s14dydj4-10 kiAEUp">test1,test1,Mailboxes,3,4,5,6,7,8,United States,10</p>
<p class="s14dydj4-10 kiAEUp">- I even changed the entries to make sure that i was not using the same test entry repeatedly</p>
<p class="s14dydj4-10 kiAEUp">3. ADSI Edits</p> <p class="s14dydj4-10 kiAEUp">- Cleared out The Entries in multiple locations to make sure there were no residual date floating around</p>
<p class="s14dydj4-10 kiAEUp">Here is the Script:</p>
#Import session from Exchange
$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://server/ -Authentication Kerberos
Import-PSSession $s -AllowClobber

# Load CSV into variable
$CSV = Import-Csv "C:\TestVehiclesEquipmentRooms.csv"

# Set up hashtables for the parameters of the different commands
$NewMailboxParams = @{
    Name =               $Line.Equipmentname
    Alias =              $Line.Alias
    OrganizationalUnit = $Line.Oupath
    Equipment =          $true
}
$SetUserParams = @{
    Identity =          $Line.Equipmentname
    Office =            $Line.Office
    Phone =             $Line.TelephoneNumber
    StreetAddress =     $Line.Street
    City =              $Line.City
    StateOrProvince =   $Line.State
    PostalCode =        $Line.ZIP
    CountryOrRegion =   $Line.Country
    Notes =             $Line.Notes
}
$SetCalProcParams = @{
    Identity =              $Line.Alias
    AutomateProcessing =    'AutoAccept'
    AllowConflicts =        $false
    AllBookInPolicy =       $true
    AllRequestInPolicy =    $false
    AllRequestOutOfPolicy = $false
}

# Loop over each line in the CSV file caling the different commands with the parameters specified above.
 foreach ($Line in $CSV) {
    New-Mailbox @NewMailboxParams
    Start-Sleep -Seconds 10
    Set-User @SetUserParams
    Set-CalendarProcessing @SetCalProcParams
}

<p class=“s14dydj4-10 kiAEUp”>I am not sure what i am doing wrong. Any help would be appreciated! Thank you in Advance.</p>

You have to move your splatting hash tables INSIDE your foreach loop. :wink:

I still tend to think that there’s a distinct difference between your example and his code. You’re not using the content of the csv for your splats.
While the following code does not work … at least on my environment

$CSV = @’
Object, ForegroundColor, BackgroundColor
“Nachricht1”, “red”, “blue”
“Nachricht2”, “yellow”, “green”
“Nachricht3”, “magenta”, “yellow”
'@ | ConvertFrom-Csv -Delimiter ‘,’

$Hash = @{
Object = $item.Object
ForegroundColor = $item.ForegroundColor
BackgroundColor = $item.BackgroundColor
}

foreach ($item in $CSV) {
Write-Host @Hash
}


does the code with the moved hash table work as expected …
$CSV = @’
Object, ForegroundColor, BackgroundColor
“Nachricht1”, “red”, “blue”
“Nachricht2”, “yellow”, “green”
“Nachricht3”, “magenta”, “yellow”
'@ | ConvertFrom-Csv -Delimiter ‘,’

foreach ($item in $CSV) {
$Hash = @{
Object = $item.Object
ForegroundColor = $item.ForegroundColor
BackgroundColor = $item.BackgroundColor
}
Write-Host @Hash
}


… explain that please. :wink: :smiley: