Problem with if/else

I'm working on a script that will import data from a CSV file and use it to set up a host of newly built.  Where I'm going to have a difficult time is that in the CSV file I Datacenter and Cluster like columns and I need to set up a foreach interviewing then vCenter to see if there is a data center by the name specified in the CSV file, and if yes, then interrogate the datacenter to see if a cluster by the name listed in the CSV file file exists and then finally add the host to the cluster and repeat to the line next to the file.  If he asks vCenter and does not have a datacenter by the name specified in the CSV file, it then creates the datacenter and the cluster, then add is the host.  I hope this makes sense.  Thanks for the help to come is to work this issue.

A slight variation which makes use of the pipeline, as appropriate, and who reads the input file only once.

Import-Csv "C:\input.csv" | %{
    $dc = Get-Datacenter -Name $_.Datacenter -ErrorAction SilentlyContinue    if(!$dc){
        New-Datacenter -Name $_.Datacenter -Location (Get-Folder Datacenters) | `        New-Cluster -Name $_.Cluster | `
        Add-VMHost -Name $_.Host -User  -Password 
    }
    else{
        $clus = Get-Cluster -Name $_.Cluster -Location $dc -ErrorAction SilentlyContinue        if(!$clus){
            New-Cluster -Name $_.Cluster -Location $dc | `
            Add-VMHost -Name $_.Host -Location $clus -User  -Password 
        }
        else{
            Add-VMHost -Name $_.Host -Location $clus -User  -Password 
        }
    }
}

Notice that to create the data center, when it is not present, you must specify the location.

I used the shadow of data originally from the vCenter centers folder.

Tags: VMware

Similar Questions

  • Problem with if/else instructions embedded in the options of the menu drop-down

    Hello

    I have a problem, try to add conditions together.

    I have a form that has so many drop-down menus with the same options of 1 to 5. However, a user does not choose the same option in any downs drop different two or more. for example if the drop-down list 1 has an option of '1' then drop-down menu 2 must have a different option, dropdown 3 must have a different option etc.

    I can't seem to get my script to run successfully. I need to combine statements.

    A person can be of any help please?

    My script for the first drop-down is:

    if (this.rawValue = Drop2.rawValue)
    { 
    
    xfa.host.messageBox("You cannot have duplicate positions for different financial threats/risks/hazards. Please choose another position!");
    
    
    }else if (this.rawValue = Drop3.rawValue){ 
    
    xfa.host.messageBox("You cannot have duplicate positions for different financial threats/risks/hazards. Please choose another position!");
    }else if (this.rawValue = Drop4.rawValue){ 
    
    xfa.host.messageBox("You cannot have duplicate positions for different financial threats/risks/hazards. Please choose another position!");
    }else if (this.rawValue = Drop5.rawValue){ 
    
    xfa.host.messageBox("You cannot have duplicate positions for different financial threats/risks/hazards. Please choose another position!");
    
    } 
    
    else if (this.rawValue == 1 && this.rawValue != Drop2.rawValue && this.rawValue != Drop3.rawValue && this.rawValue != Drop4.rawValue && this.rawValue != Drop5.rawValue){
    FINANCIAL_1_1.rawValue = FINANCIAL_1.rawValue;
    } else if (this.rawValue == 2){
    FINANCIAL_1_2.rawValue = FINANCIAL_1.rawValue;
    } else if (this.rawValue == 3){
    FINANCIAL_1_3.rawValue = FINANCIAL_1.rawValue;
    }
    
    

    It doesn't seem to work.

    Send the form to [email protected] and I can take a look.

    Steve

  • JavaScript problem with if/else instructions

    Hello!

    I have a test page.  The goal is to hide the following custom button when you enter the page and allowing it, when the test has passed or failed for the last time.  Then if the user navigates on the same quiz page, the next button should already be displayed.  I'm doing it by assigning a value of 0 or 1 to a variable and triggering an if statement if the value withdraws.

    When you enter the page I run the following code:

    var slideRef = window.cpAPIInterface.getCurrentSlideIndex ();                        Gets the current page number

    CP. Hide ('next_button_KBQ_' + slideRef);                                                        hide the next button

    var isTaken = window.cpAPIInterface.getVariableValue ("L4_KBQ1_taken");   assigns a variable value (variable defined in Captivate with an initial value of 0)

    Console.log ("isTaken value is" + isTaken);

    If (isTaken = 1) {//if this quiz page has been adopted, following button

    CP. Show ('next_button_KBQ_' + slideRef);

    Console.log ("Enabling Next Button");

    } else if (isTaken = 0) {}

    CP. Hide ('next_button_KBQ_' + slideRef);                                                    This should not be necessary, but it's here for testing purposes

    Console.log ("next button should be disabled");

    }

    success and a part of the last attempt of the quiz I run the following code:

    var slideRef = window.cpAPIInterface.getCurrentSlideIndex ();

    window.cpAPIInterface.setVariableValue ("L4_KBQ1_taken", 1);                   assign the variable with a value of 1

    CP. Show ('next_button_KBQ_' + slideRef);

    When I run the course, I get the following console result:

    isTaken value is 0

    Next button activation

    If the button is displayed from the start.  If I take the test and return to the page, the bed console

    isTaken value is 1

    Next button activation

    Then the variable is changing, Captivate reads the value of the variable very well, but it ignores the conditions and display the button in any case from the beginning.  What happens here?

    Thank you!

    You need to use is during the comparison, not =. In addition, you need another if, just another because there are only 2 options.

    If ( == 1 isTaken) {//if this quiz page has been adopted, following button

    CP. Show ('next_button_KBQ_' + slideRef);

    Console.log ("Enabling Next Button");

    } else {}

    CP. Hide ('next_button_KBQ_' + slideRef);                                                    This should not be necessary, but it's here for testing purposes

    Console.log ("next button should be disabled");

    }

  • problem with if/else with liquid trying to fill out a form in advance

    I'm trying to automatically fill out parameters with a custom using liquid - field you see something wrong with the statement ' if/else '? AutoFill works OK if it is not empty but is unable to do the part "else" (replace with "New South Wales" If empty) - thanks in advance!

    Billing booking status < label for = "CAT_Custom_20031893_187341" > < / label >

    < select name = "CAT_Custom_20031893_187341" id = "CAT_Custom_20031893_187341" class = 'required cat_dropdown' >

    "< option value =" ">--please select--< / option >".

    {% If CAT_Custom_20031893_187341! = "" %}}

    < option value = '{module_customerfield, 187341, 20031893}' selected = "selected" > {module_customerfield, 187341, 20031893} < / option >

    < option value = "New South Wales" > New South Wales < / option >

    {%-%}

    < option value = "{module_customerfield, 187341, 20031893}" > {module_customerfield, 187341, 20031893} < /op ing >

    < option value = "New South Wales" selected = "selected" > New South Wales < / option >

    {endif %}

    < option value = "Queensland" > Queensland < / option >

    < option value = "South Australia" > South Australia < / option >

    < option value = "Tasmania" > Tasmania < / option >

    < option value = "Victoria" > Victoria < / option >

    < option value = "Western Australia" > Western Australia < / option >

    < / select >

    < script type = "text/javascript" >

    document.getElementById('CAT_Custom_20031893_187341').value = "{module_customerfield, 187341, 20031893};

    < /script >

    Not all variables 'empty' corresponding to the empty string.

    Try something like {% if CAT_Custom_20031893_187341 and CAT_Custom_20031893_187341 != "" -%} .

  • Want 700-327c graphic problem with Google Earth

    Lettering not appearing is not in some areas: Search button, tools > Options (no registration). Entry displays not to when you type in the search box.  View do not come out correctly.  Graphics card: Intel (r) Graphics HD 4600 worm: 10.18.10.3621(5/17/14). I tried to update by Intel, but the answer was that this card had been changed by the manufacturer of the computer, ask the update through HP.

    Have you tried UN/reinstall.

    Have not had problems with something else.

    Chop21, welcome to the forum.

    This isn't a hardware problem.  I suggest that you go to their support help page.  They are the experts on their program.

    Please click on the Thumbs up button '+' if I helped you and click on "Accept as Solution" If your problem is resolved.

  • Download a file should implement an option to open the file or save it - for some reason any now just downloading it straight to the download folder. Why? Problem with Firefox or something else?

    Download a file would normally bring up an option to open the file with the appropriate program or save it - for some reason any now just downloading it straight to the download folder. Why? Problem with Firefox or something else? It is very frustrating - sometimes, you want the first opened file so it can be discarded or stored in a different location.

    Find the type of file in the Firefox -> Options -> Applications Panel, open its menu drop-down and select 'ask '. To reset all the actions of download, delete the mimeTypes.rdf file in your Firefox profile folder (or rename the mimeTypes.rdf X if you want to save as a backup). The file will be regenerated with all types of files, restore the default actions.

    For more information, see application Panel - set how Firefox handles different file types and change what Firefox does when you click on or download a file .

  • Anyone else having problems with registering for hotmail today?

    Hotmail

    Anyone else having problems with hotmail registration today.  I'm really p...d like I got problems for part of the day of yesterday too... not very reliable and very frustrating to say the least

    Hello DianneCarrington,

    The best place to ask your question of Windows Live is inside Windows Live help forums. Experts specialize in all things, Windows Live, and would be delighted to help you with your questions. Please choose a product below to be redirected to the appropriate community:

    Windows Live Mail

    Windows Live Hotmail

    Windows Live Messenger

    Looking for a different product to Windows Live? Visit the home page Windows Live Help for the complete list of Windows Live forums to www.windowslivehelp.com.

  • Is a message "cannot find server" a problem with Internet connectivity or something else?

    Original title: Net question?

    When I get a message "cannot find server", is this a problem with internet connectivity or something else?  MSN and explore will be not open.  Thank you.

    Hi Aziz,.

    The Cable Guy came and installed a new modem and the new thicker cable.  So far so good.  Thanks for your reply.

  • Is anyone else having problems with gMusic?

    My gMusic application worked fine, but now it doesn't work at all. Never. Does anyone else have this problem? I want to X 2 (which I LOVE) and Google game works fine on my phone, but the gMusic app will not work on the desire. He is used to, maybe up to a month or two ago. There is not a single song in my library that will play. I tried to uninstall and reinstall the application... no luck. I thought that maybe my files were corrupt, but as I said, it works very well on my phone, so I don't know what the deal is.

    I can't say for sure, but it could be a problem with the application itself however, I'd suggest a refresh on the system running if you don't have it already. Then reinstall the application.

    Refresh your PC without affecting your files

    If your PC does not perform as in the past, and you don't know why, you can refresh your PC without delete all of your personal files or change your settings.

     

  • Is anyone else having problems with Windows 8 when your typing and e-mail? For some reason, it comes out constantly to the tile screen while I type making me about starting more.

    Is anyone else having problems with Windows 8 when your typing and e-mail? For some reason, it comes out constantly to the tile screen while I type making me about starting more.

    Hi Chaz,

    I thank you for your message and gives us a chance to help you. I see that the Mail app closes while you are typing an email.

    Please answer these questions to get a better understanding of the issue.
    1 have changes made to your computer before this problem?
    2 shut down other applications while they are in use?
    3. do you get an error code?

    You can try these methods to check whether the problem is resolved.

    Method 1: Run the troubleshooter of app.

    http://download.Microsoft.com/download/F/2/4/F24D0C03-4181-4E5B-A23B-5C3A6B5974E3/apps.diagcab

    Open this link to launch the troubleshooter.

    Method 2: Update the application.

    Method 3: Reinstall the application.

    This link has the steps that you can follow to update and reinstall the application.

    http://Windows.Microsoft.com/en-us/Windows-8/what-troubleshoot-problems-app

    Feel free to use the forum for any other issue of Windows, you may have.

  • Someone else has problems with their computer crashing once they have installed the Nik for Photoshop CC filters?

    Someone else has problems with their computer crashing once they have installed the Nik for Photoshop CC filters?

    Hi amlportraiture,

    Could you please let us know the exact version of Photoshop you're working on, also did you copy the Plugins and move it to the folder Plugins in Photoshop?

    And please make sure you have the latest version of Nik Collection Installer on the computer.

    Kind regards

    Tanuj

  • Anyone else have problems with the unethical choice to use the word "updated"?

    Does anyone else have problems with choosing the unethical to use the word "update" when what is going on is an UPGRADE that requires of new licences and payment?

    "updates" don't involve payment, make "improvements".  Given that you posted in the forum of creative cloud, if you have a subscription paid and that you are asked to pay more than the cost of the subscription it is more likely a problem with your installation/account.

  • Problem with Cloud - on MacBook pro, when I opened the window CC, all I get is welcome Aps active community.  a blue dial spining but nothing else

    Problem with Cloud - on MacBook pro, when I opened the window CC, all I get is welcome Aps active community.  a blue dial spining but nothing else

    Hello

    I suggest you fine the link below and it will help you.

    Does not open App | Wheels of progress turn continuously

    Concerning

    Maansee

  • Is anyone else having problems with the crop tool in LR6.

    Is anyone else having problems with the crop tool in LR6.
    My PC crashes sometimes when I use the crop tool in LR6. It seems fairly random, and I never had this problem in LR5.

    Have you tried to disable the GPU acceleration in Lightroom preferences?

  • When using Firefox I get popups frequent AVG Antivirus saying that Firefox uses an excessive amount of memory - is this a problem with Firefox or AVG or something else?

    Using Windows 7 with all updates. Computer has 6 GB of ram and has no problems with other sites

    If these messages back, see AVG support on how to increase the threshold trigger the trigger for this message. With 6 GB of RAM, there is no reason for Firefox using less than 10% of your RAM to be a problem and cause this message appears. IMO, the alarm should not trigger up to about 50%.

Maybe you are looking for

  • I need help please error - 1

    Hello guys. I have a problem with my iPhone 6 and I can't find a solution for it. The iphone displays the apple logo and just a way connect to iTunes logo. I tried to restore the phone but the restoration progressed to near 100% and then error - 1 an

  • How to recognize fake battery

    Hello I recently bought a new battery for my laptop, and I suspect that it is false. It really looks like my original battery, but the first thing I noticed is that when I press on it, on the sides (especially upper part with sticker) plastic parts u

  • Satellite U400-22n - how to change the button mute for Led lighting

    Hello I can't turn off lighting on shortcut keys. The shortcut key to disable the LED has decided to change himself to put on mute. Does anyone know how I can pass this mute button to turn off the lights, or simply how can I turn off? Thanks in advan

  • Scanning issue

    I can scan a legal size using HP Photosmart C6200 document?

  • Dell Inspiron 1525 laptop hinges

    I have a laptop Dell Inspiron 1525 and I'm wanting answers to a "quick fix" for laptop hinges. My monitor is wobbly. I am unwilling to put any expensive money in it what so ever because this isn't worth that I am buying a new laptop. Any suggestions