none
Trying to use multiple if statements to set a variable in my script RRS feed

  • Question

  • I am importing a csv file to create user accounts.. i have it working.. but now i want to have the script look at a variable, and based on that variable set other variables, like the ou or home directory path etc..

    here's what i have so far.. it seems to select the 2nd option ASH unless i # it out then it selects the first option..i am clearly missing something simple here.... i can't just use an else statement as i will need many lines of logic to support the many different ou's, home dir shares etc.. globally...

    import-csv $csv | foreach-object {

                       

     $site=$_.site
                       $HomeDArl= "\\teleflex\global\home\medical\na\arl"
                       $HomeDASH= "\\ashfs01.arrowintl.com\user"

                            if ($site='ARL'){
                                $homed = $HomeDArl
                            }
                            if ($site='ASH'){
                                $homed =$HomeDASH 
                            } 

    }


    • Edited by escott0699 Thursday, June 19, 2014 9:28 PM
    Thursday, June 19, 2014 9:11 PM

Answers

  • This is what the Switch command was made for.

    see:

    get-help about_switch


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    • Marked as answer by escott0699 Thursday, June 19, 2014 9:47 PM
    Thursday, June 19, 2014 9:26 PM
    Moderator

All replies

  • This is what the Switch command was made for.

    see:

    get-help about_switch


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    • Marked as answer by escott0699 Thursday, June 19, 2014 9:47 PM
    Thursday, June 19, 2014 9:26 PM
    Moderator
  • Thanks for the push in the right direction..

    Import-CSV $filepath | ForEach-Object {
                                  $site=$_.site
                                   switch ($site) {
                                    Arl {$homed = "\\teleflex\global\home\medical\na\arl"}
                                    Ash {$homed ="\\ashfs01.arrowintl.com\user"}
                                  }

    }

    Thursday, June 19, 2014 9:48 PM