Reputation: 35
Wondering if anyone could please assist with below.
I've tried a few different ways to get the below code working. Have three possible outcomes.
#test for UM extension number#
$um1 = Get-UmMailbox $user -ErrorAction SilentlyContinue | Select @{name=”Extensions”;expression={$_.Extensions -join “;”}} | ?{ $_.Extensions -match '^\d\d\d\d\d$' }
$umextensionnumber = if ($um1) { $um1.Extensions } elseif (!$um1) { 'UM not enabled' } else { 'No UM Extension Number' }
Any help would be greatly appreciated.
Upvotes: 0
Views: 40
Reputation: 174485
Way easier to read (and reason about) with nested if
's instead:
$umextensionnumber = if($um1){
# UM is enabled, let's check the extension:
if($um1.Extensions -match '\d\d\d\d\d'){
$um1.Extensions
}
else {
"No extension found"
}
}
else {
"UM not enabled"
}
Upvotes: 2