The Import-Csv cmdlet reads the file and stores each line as an object
in the variable $users . The property names are determined by the header structure of the CSV file,
which is covered in more detail later in this section. If the content structure of the CSV file does not
match what is expected by Import-Csv or if the file is not found, the command fails.
# Read input from the CSV file
$users = (Import-Csv $CSVUpath)
The last code segment is where the bulk of the work is actually done and the mailbox - enabled accounts
are created using the cmdlet New-Mailbox . This segment uses the foreach loop command to iterate
(step through) a collection of items, in this case the objects stored previously in the $users variable. The
syntax of foreach is as follows:
foreach ($ < item > in $ < collection > ) {command_block}.
The command executes the contents of the script block on each object in the collection one at a time.
Simply stated, the foreach command in the sample script does this: for each individual object ( $user )
in a collection of objects ( $users ), execute the script block ( New-Mailbox... ).
The $user variable represents the current object being acted upon. Inside the script block, dot notation is
used to de - reference each object property value for that object.
Pages:
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582