Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Trouble with switch in PowerShell

$
0
0
$SamName = Read-Host 'PLEASE ENTER THE USERNAME OF THE PERSON YOU ARE BUILDING THE PC FOR' 
$root = [ADSI]''
$searcher = New-Object System.DirectoryServices.DirectorySearcher($root)
$searcher.filter = "(&(objectClass=user)(sAMAccountName= $SAMName))"
$name = $searcher.findall()
$ADUser = [ADSI]$Name.path
$ADUserDept = $ADUser.department

## Determine Department Code based on AD User Info


switch -regex ($ADUserDept)
        {
        "Private Client Advisors" {$DeptCode = "0001"}"PCA Portfolio Accounting and Reporting" {$DeptCode = "0083"}"Institutional Sales" {$DeptCode = "0002"}"Institutional Sales (New York)" {$DeptCode = "0010"}"Institutional Sales (Boston)" {$DeptCode = "0011"}"Institutional Sales (San Francisco)" {$DeptCode = "0012"}"International Sales" {$DeptCode = "0003"}"International Sales (Zurich)" {$DeptCode = "0014"}"International Sales (London)" {$DeptCode = "0404"}"International Sales (Tokyo)" {$DeptCode = "0445"}"International Sales (Vaduz)" {$DeptCode = "0013"}"NASDAQ Trading" {$DeptCode = "0061"}"Institutional Equity & Trading" {$DeptCode = "0062"}"William Blair Select" {$DeptCode = "0025"}"Corporate & Executive Services" {$DeptCode = "0026"}"IM Administration" {$DeptCode = "0041"}"Mutual Funds Administration" {$DeptCode = "0042"}"Wealth Management" {$DeptCode = "0052"}"Mutual Funds Distribution" {$DeptCode = "0056"}"IM Research" {$DeptCode = "041A"}"IM Institutional Marketing" {$DeptCode = "041B"}"IM Intermediary Distribution" {$DeptCode = "041C"}"IM Counseling" {$DeptCode = "041D"}"IM Institutional" {$DeptCode = "041E"}"IM Guidance" {$DeptCode = "041G"}"IM London" {$DeptCode = "041L"}
        'Corporate Finance' {$DeptCode = "0040"}"Corporate Finance (Shanghai)" {$DeptCode = "0044"}"Corporate Finance (San Francisco)*" {$DeptCode = "0045"}"Corporate Finance (Sao Paulo)" {$DeptCode = "0046"}"Corporate Finance (Boston)" {$DeptCode = "0048"}"Corporate Finance (New York)" {$DeptCode = "0050"}"Corporate Finance (London)" {$DeptCode = "0440"}"Syndicate" {$DeptCode = "0060"}"Corporate Finance - Desktop Publishing" {$DeptCode = "0999"}"Corporate Finance (Frankfurt)" {$DeptCode = "0043"}"Municipal Bonds" {$DeptCode = "0005"}"Municipal Bonds (New York)" {$DeptCode = "005N"}"Debt Capital Markets" {$DeptCode = "0007"}"Taxable Fixed Income" {$DeptCode = "0065"}"Taxable Fixed Income (New York)" {$DeptCode = "065N"}"Taxable Fixed Income (San Francisco)" {$DeptCode = "065S"}"Research" {$DeptCode = "0094"}"Research (Boston)" {$DeptCode = "094B"}"Research (New York)" {$DeptCode = "094N"}"Research (San Francisco)" {$DeptCode = "094S"}"Research (Shanghai)" {$DeptCode = "0032"}"Management Information Services" {$DeptCode = "0084"}"Management Information Services (D)" {$DeptCode = "084D"}"Business Information Center" {$DeptCode = "0085"}"Printing & Supplies" {$DeptCode = "0086"}"Mailroom" {$DeptCode = "0087"}"Human Resources" {$DeptCode = "0089"}"General Office" {$DeptCode = "0090"}
        'Finance' {$DeptCode = "0092"}"Brand Marketing & Communications" {$DeptCode = "0093"}"Retail Order Desk" {$DeptCode = "0095"}"Operations-Cashiering" {$DeptCode = "0096"}"Legal and Compliance" {$DeptCode = "0097"}"Administration" {$DeptCode = "0098"}"General Counsel" {$DeptCode = "0082"}"Planning" {$DeptCode = "0091"}"London" {$DeptCode = "0004"}"Capital Partners" {$DeptCode = "0035"}"Funds Placement Group" {$DeptCode = "0049"}
        default {$DeptCode = "0000"}
}    

Write-Output $ADUser.Name
Write-Output $ADUserDept
Write-Output $Deptcode

I am using the above code as a test script for a bigger project.  I thought all was working well until I enter a user name of someone in the Corporate Finance department.  

The correct name comes back.

The correct Department Name comes back

The code for Finance is returned.  

What am I missing here?


Matt Dillon


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>