Prev | Current Page 606 | Next

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

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

This also results in a true condition if a Distribution Group is found, and a false
condition if not found. Therefore the if statement only executes when a Distribution Group is found.
if ($dgdept = (Get-DistributionGroup | where {$_.name -like `
???*$($user.department)*???}))
{
The Add-DistributionGroupMember cmdlet is used to add the user specified by Member to the
Distribution Group stored in the variable $dgdept .
Add-DistributionGroupMember -Identity:$dgdept `
-Member:$user.name -ErrorVariable err
The if statement that follows the Add-DistributionGroupMember command checks to see if the
operation was successful by testing if $err is not equal to null. If true, the error captured in $err is used
along with the text stored in the $errorString variable plus the text string shown to construct the error
message written to the log file. Also $noErrors is set to $false and $errorTotal is incremented by 1.
If ($err -ne $null)
{
$thiserror = $errorString + ???addition to Distribution Group
$($dgdept.name) failed with error:???
out-file $logfile -append -inputobject $blankline, `
$thiserror, $err[0], $blankline
$noErrors = $false
$errorTotal += 1
}
Part IV: Automating Administration
448
If a Distribution Group is not found, the if statement is skipped and the else statement that follows it
executes instead.


Pages:
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
drukarki fiskalne kraków willa karmazyn międzyzdroje www.books61.hobbitstory.com terapia magnetyczna Informacje o hostingu