Below simple code will check to see if mailbox exist, if not script will stop. It is easy to use same logic to setup similar conditions for similar tasks.
Clear-Host
write-host "-----------------------------
$targetmb = Read-Host "()_Please Provide user name"
write-host "-----------------------------
#()_.Vars
$sc = "SilentlyContinue"
write-host $null
Write-Host "(-)_.Checking mailbox:[$targetmb]" -f Yellow
$mb = get-mailbox $targetmb -ErrorAction $sc
if ($mb -eq $null)
{
write-host "`tThe target mailbox does NOT exist:" -n; Write-Host "[$targetmb ]" -f Red -b Black
break;
}
else
{
write-host "`tLocated mailbox:" -n; Write-Host "[$targetmb]" -f Green -b Black
}
|
Casey DeDeal
Azure Certified Solutions Architect
Principal Systems Engineer
https://msazure365.blogspot.com/ (blog)
https://simplepowershell.blogspot.com/ (blog)
https://twitter.com/Message_Talk (Twitter)
Azure Certified Solutions Architect
Principal Systems Engineer
https://msazure365.blogspot.com/ (blog)
https://simplepowershell.blogspot.com/ (blog)
https://twitter.com/Message_Talk (Twitter)
No comments:
Post a Comment