I have the following If
block which in a logon script which I am re-writing:
If ($distinguishedname -match 'Joe Bloggs') {
Map-Drive 'X' "\\path\to\drive"
}
If ($distinguishedname -match 'Steve Bloggs') {
Map-Drive 'X' "\\path\to\drive"
}
If ($distinguishedname -match 'Joe Jobs') {
Map-Drive 'X' "\\path\to\drive"
}
Which obviously needs to be re-written as an If/Else
statement (as each user only has 1 name!) However, I prefer the look of the following switch -Regex
method:
switch -Regex ($distinguishedname) {
'Joe Bloggs' {Map-Drive 'X' "\\path\to\drive"; break}
'Steve Bloggs' {Map-Drive 'X' "\\path\to\drive"; break}
'Joe Jobs' {Map-Drive 'X' "\\path\to\drive"; break}
}
My question is - would using a switch in this manner have any impact on the performance of this function? It must be better than the above (if/if/if
), as not every possibility is evaluated each time, but would the switch
be faster than an ifelse/ifelse/else
?