
Part IV: Automating Administration
460
The only if statement in this function uses the Get-PublicFolder cmdlet to see if a folder with a name
that matches the name of the user already exists. The script assumes that all user - related public folders
are to be created under a top level folder named
corporate . Therefore the value used to identify the
public folder for which the test is checking is constructed using the text
\corporate and the value
stored in the Name property of the user mailbox object stored in
$userMB .
The same segment of code that works out the default public folder store for the user later in the script is
also used to determine the name of the server holding the public folder store, which is stored in the
variable
$server .
If the
Get-PublicFolder command returns a public folder object, then the condition evaluates true and
the statement executes.
$hasFolder is set to $true and an error message is displayed to inform the
administrator that a public folder for this user already exists. The value of
$hasFolder is returned to the
command that called
validateFolder and all processing for the function is complete.
if (get-publicfolder -identity:”\corporate\$($userMB.name)” -server:$server)
{
$hasFolder = $true
Write-Host -fore yellow “`nA Public Folder for this user already exists.`n”
return $hasFolder
}
The last command in the function only executes ...