Prev | Current Page 584 | Next

Joezer Cookey-Gam, Brendan Keane, Jeffrey Rosen, and Jonathan Runyon

"Professional Windows PowerShell for Exchange Server 2007 Service Pack 1"


param([string]$CSVUpath)
The second code segment ??? turns off ??? errors normally displayed at the console by setting the automatic
variable $ErrorActionPreference to the value of SilentlyContinue . This setting affects error
reporting only in the scope of the script; the way errors are displayed returns to normal after the script
completes. Any errors encountered during script execution are interpreted by the script. If the user needs
to take action, a user - friendly message is displayed. All other errors are recorded to the log file:
# Turn off error reporting to the display
$ErrorActionPreference = ???SilentlyContinue???
The third code segment defines a function block called ValidatePath that is used to validate the path
to the CSV file by testing the input value and whether or not it resolves to an existing file. It is standard
practice to define functions up front in a script because they have to be stored in memory before they can
be processed later in the script.
Part IV: Automating Administration
436
First, the $notValidPath variable is created to store the results of the tests. It is set to $false before the
tests are run and changes to $true if one of the tests fails. The value of $notValidPath is returned to
the command that calls this function, and will be used to determine if script processing is halted or
continues:
# This function validates the path to the CSV input file
function ValidatePath
{
$notValidPath = $false
Next the value of the $CSVUpath variable is tested to see if a value was entered at the command line
when the script was run, and if so whether that value resolves to an existing file.


Pages:
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
Regały Danny pieniny noclegi agencja reklamowa poznań hotele