Create exchanges with table to hash foreach loop

I am a beginner in PowerShell and PowerCLI.

I would like to create a virtual switch with several exchanges and VLANID and then assign a network adapter

This code works for me:

$esxihost = "esx01.

SE connect-VIServer-Server $esxihost

$vSwitch = New VirtualSwitch - VMHost $esxihost - name vSwitch3

$vPortGroup = New-VirtualPortGroup - $vSwitch - name ADM VLanId VirtualSwitch - 1012

$vPortGroup = New-VirtualPortGroup - $vSwitch - name of the VLanId man VirtualSwitch - 1020

$vPortGroup = New-VirtualPortGroup - $vSwitch - name test1 VirtualSwitch - VLanId 1021

$vPortGroup = New-VirtualPortGroup - $vSwitch - name of test2 VirtualSwitch - VLanId 1022

$vPortGroup = New-VirtualPortGroup - $vSwitch - name test3 VirtualSwitch - VLanId 2000

Game-VirtualSwitch - VirtualSwitch $vswitch - Nic vmnic3 - confirm: $false

But I think something like this would be much more elegant:

$esxihost = "esx01.

SE connect-VIServer-Server $esxihost

$vSwitch = New VirtualSwitch - VMHost $esxihost - name vSwitch3

$vlans = @{'}
'adm' = 1012; `
'man' = 1020; `
'test1' = 1021; `

"test2" = 1022; `

"test3" = 2000
}

{foreach ($vlans items)

$vPortGroup = news-VirtualPortGroup - $vSwitch - name $vlans VirtualSwitch. Key -VLanId $vlans. Value

}

Game-VirtualSwitch - VirtualSwitch $vswitch - Nic vmnic3 - confirm: $false

But I can't get the foreach loop to work. I'm not sure on the three points marked in bold in the foreach loop. Can someone give me a clue...?

Thank you.

Anders

You store data in a hash table.

You cannot use the ForEach loop, as you would for a regular table, but you can use the GetEnumerator method.

Something like that

$esxihost="esx01"
Connect-VIServer -Server $esxihost
$vSwitch =  New-VirtualSwitch -VMHost $esxihost -Name vSwitch3
$vlans = @{
    "adm" = 1012;
    "man" = 1020;
    "test1" = 1021;
    "test2" = 1022;
    "test3" = 2000}

$vlans.GetEnumerator() | %{
    $vPortGroup =  New-VirtualPortGroup -VirtualSwitch $vSwitch -Name $_.Key -VLanId $_.Value
}

Set-VirtualSwitch -VirtualSwitch $vswitch -Nic vmnic3 -Confirm:$false

Tags: VMware

Similar Questions

  • Possible to Exchange temporary table with composite range-hash partitioned table?

    Hello

    Using oracle 11.2.0.3

    We want to clean up the data in some of our existing partitioned table.

    Afetr updates check spped that is too slow for us.

    Current table is partitioned the inetrval compoiste range-hash table.  Also it is compressed - enabled for compression of basis as well

    An interval of 1 month and 1 partition by month and 4 secondary partitions in the partition of ecah.

    You want to create tenp table with the data of celan and exchange the data in this table in the 'dirty' uisng existing partitions partition exchnage.

    Is this possible?

    The plan is

    1) create temporary table containing data for 1 partition (1 month worth of data)

    (2) clean the data here

    (3) create new temporary table with these specific data which compressed and discovered partitioned with 4 secondary partitions

    (4) table 3 for swap partition dirty using partition excahnge.

    Thaks

    I think that this can be done with a combination of Exchange and Split partition partitions. Prior to Oracle 11 g, only way of redefining tables online was DBMS_REDEFINITION package. Now, you can redefine the use of partitions for Exchange & Split. Check

    http://www.Oracle-base.com/articles/Misc/partitioning-an-existing-table-using-Exchange-partition.php

    Maintenance of Partitions

    Kind regards

  • Partiton Exchange with a table of partitoned

    Hi all

    Basically, I want to exchange a partition with a partition to another table. < < Not with data from the source, only the subset of data from the source table > >

    I am not able to do this, because the swap partition syntax allows only to exchange the partition with an entire table... According to below syntax

    Target WITH the source TABLE of the EXCHANGE PARTITION

    Is it possible I can do Exchange partition with a partition specific to this table in the source as below

    SWAP PARTITION WITH source TABLE p1_target_jan_2013 where month = "Jan 2013"

    OR

    SWAP p1_target_jan_2013 WITH TABLE source partition p1_jan_2013 PARTITION

    We want to move existing data from a tab1 in the table (Source) that is already partitioned on the date column for each month.

    Data in the source given cans to zero for each month.

    that is when ever some Calc is run again for a given month (e.g. Jan 2013), existing data related to "Jan 2013" is given first and then deleted again inserted for this month ' Jan "»
    2013 so to keep a history of all data, we want to keep moving data to the data in the history before deleting.

    As huge data are involved, can use PARTITION EXCHNAGE, but also located above, as I want to exchange the partition with the subset of rows of a table source'm not able to do this.

    Can someone help me please...

    Kind regards...

    I suppose that there are two partitioned tables (the letters represent the content, not the name of the partition):

    • PARTITIONED_TABLE_SOURCE (A, B, C)
    • PARTITIONED_TABLE_TARGET (D, E, F)

    If I want to get the data from the partition A to replace the data in the partition D, I'd be:

    • Exchange A Partition with a self-help support table H (defined with the same columns, index a etc)
    • now, my PARTITIONED_TABLE_SOURCE contains partitions (H, B, C) and A is a stand-alone table (of course I mean the data and not the partition since H names will be named A after the Exchange)
    • Swap Partition D with the self-help support table has (once again a stands for the content and not the name of the object): so now PARTITIONED_TABLE_TARGET contains (A, E, F)

    Maybe it would be more concese with a code example...

  • Table created from a text input fields for loop

    I am new to AS3 and animate CC. I'm not a programmer. I learn how the code I want (from YouTube and various web sources). I put the next set of various web tutorial. What I'm trying to do is create a user input field and input variable which will set the number of new text fields created by a loop for. Then store the text fields in a table to access their values to use elsewhere. The problem is, I don't know how to access the values of the input fields created in the table.  The loop for works to create the new text entry fields, I do not know how to retrieve their values.  In fact, I don't know even if the text that I entered new fields is currently stored in the table. I think that the text field itself, as an object, is stored but not the text I enter the text field (which is what I want).  I hope someone can help me...

    to import flash.display.SimpleButton;

    import flash.events.Event;

    import flash.text.TextField;

    import flash.text.TextFormat;

    import flash.text.TextFieldType;

    var captureText: Array = new Array();               meant to be the text of "aTextFields" of the "aTextFields" table values

    var text3: String;                                               variable as containing "captureText [0]"

    var aTextFieldsText = new TextField();             dynamic text field called 'TextFieldsText '.

    aTextFieldsText.border = true;

    aTextFieldsText.width = 100;

    aTextFieldsText.height = 25;

    aTextFieldsText.x = 300;

    aTextFieldsText.y = 55;

    addChild (aTextFieldsText);                              Add "TextFields" to the value of the scene and the variable "Text3" poster

    var nTextFields: number = 2;                          creates the number of input fields, and would be attached to an entry on the scene.

    var aTextFields: Array = new Array();              array that contains ""input TextFields text fields " "

    for (var int i; i < nTextFields; i ++) {/ / loop for who created him ""text fields of seizure of TextFields " based on the "nTextFields" value"}

    aTextFields [i] = new TextField();

    aTextFields [i] .Guy = "entry";

    aTextFields [i] .width = 100;

    aTextFields [i] .height = 25;

    aTextFields [i] .border = true;

    aTextFields [i] .text = "";

    aTextFields [i] .x = 150;

    aTextFields [i] there = 15 + i * aTextFields [i] .height + i 5;

    captureText.push (aTextFields [i]);                 Push the table 'captureText '.

    addChild (aTextFields [i]);

    }

    var MyButton: SimpleButton = new Button;

    myButton.x = 339;

    myButton.y = 268;

    addChild (myButton);

    myButton.addEventListener (MouseEvent.CLICK, test1, false, 0, true);  "Text3" variable on captureText set button [0]

    function test1(event: MouseEvent): void {}

    Text3 = captureText [0];                                "Text3" variable to captureText [0]

    aTextFieldsText.text = text3.toString ();       displayed in the text field "[TextField object]" instead of the text value of the entry at index [0]

    trace ("aTextFields =" + aTextFields);

    trace ("captureText =" + captureText);

    trace ("Text3 =" + Text3);

    }

    captureText is an array of textfields and not a textfield. This line:

    Text3 = captureText [0];

    Maybe should be:

    Text3 = captureText [0] .text;

  • Need help with an Export-CSV and ForEach loop

    Hi guys, I'm total NOOB in CLI so please forgive the stupid question.

    I need your expert advice for the very large environment and will award points.

    I have a working script that alerts to our logout ESXi hosts, maintenance and NotResponidng mode

    His job well, but need to send a mail to all three of our VCenters

    Current script only works for a VC at a time. How do I ForEach and always the hose of the same body CSV and HTML

    It would be nice to have an HTML and CSV output that looks like this (assuming that there are currently disconnected etc.)

    I have a set of credentials, that work on all 3 of my VC

    VC1

    Host1 disconnected

    Host2 NotResponding

    VC2

    Host3 disconnected

    Host4 NotResponding

    VC3

    No disconnected/maintemance/notresponding hosts for VC3

    Here is my current code, etc. of the hidden passwords >

    # Clear old sessions
    Disconnect VIServer VC01-confirm: $false

    # VC01 VC check for disconnection and Maintenance mode and does not
    SE connect-VIServer-Server VC01 - FakeUSer username-password FakePassword

    $Report = get-VMhost-State disconnected, maintenance, NotResponding | SELECT name, connectionstate

    # scan info to be html and give him a date stamp

    $ReportHtml = $report | ConvertTo-Html | Out-string

    # Write CSV file and give it a character of data

    $filePath = "C:\PS\Output".
    $filename = "VC01disconnectedHosts".
    $CurrentDate = get-Date
    $CurrentDate = $CurrentDate.ToString ('MM-dd-yyyy_hh-mm-ss')

    $Report | Export-Csv "C:\PS\Output\VC_$Currentdate.csv".

    # Send the info by Mail

    Send-MailMessage-to [email protected] - subject VMwareMorningcheckVC01$ CurrentDate '
    SmtpServer - mail.sanlam.co.za - from [email protected] '
    -BodyAsHtml-body $reportHtml - accessories 'C:\PS\Output\VC_$CurrentDate.csv '.

    Thank you in advance for help.

    You could use a ForEach loop through all vCenters and combine the results in a $1 report.

    Something like that

    $vCenters = "VC01","VC02","VC03"
    
    # Clear old sessionsDisconnect-VIServer $vCenters -Confirm:$false
    
    $report = @()# Check VC VC01 for Disconnects and Maintenance mode and Not Respondingforeach($vc in $vCenters){  Connect-VIServer -Server $vc -User FakeUSer -Password FakePassword
    
      $Report += (Get-VMhost -State Disconnected,Maintenance,NotResponding | Select @{N="VC";E={$vc}},name ,connectionstate)  Disconnect-VIServer $vc -Confirm:$false}
    
    # parse info to be html ,and give it date stamp
    
    $ReportHtml = ($report | ConvertTo-Html | out-String)
    
    # Write out CSV file and give it a Data Stamp
    
    $CurrentDate = Get-Date -Format 'MM-dd-yyyy_hh-mm-ss'$filename = "C:\PS\Output\DisconnectedHosts-$($CurrentDate).csv"
    
    $Report | Export-Csv -Path $filename -NoTypeInformation -UseCulture
    
    # Send info with Mail
    
    Send-MailMessage -To [email protected] -Subject VMwareMorningcheck$CurrentDate `-SmtpServer mail.sanlam.co.za -From [email protected] `-BodyAsHtml -Body $reportHtml -Attachments "C:\PS\Output\DisconnectedHosts-$($CurrentDate).csv"
    

    I added the property vCenter for each line in the report

  • Addition of the new Image and text to an existing Page created with Tables

    Work in DW 5.5

    I try to add a new image/link and a small amount of text to an existing web page that was created with tables and centered.  I use AP div tags. One for the image and one for the text.  Everything works fine, but I can't get the new anchor points and to re - center with the rest of the page.  I'm not able to get around the "absolute positioning".  I tried different solutions of various tutorials but I can't make them work with tables.

    Added items are a Facebook button and text.

    Go to: http://www.sugarhollowfarms.NET/index.html See the problem.

    Help, please. I'm not that experienced.

    First, make a back up of the page before you implement the changes below!

    Take the bit of code below to

    and insert it directly after the opening tag div FWTableContainer and before your opening table tag (see location below):

    Then add - position: relative; -to the css of FWTableContainer (as shown below):

    {#FWTableContainer209091602}

    / * The div master to make sure that our contextual menus get properly aligned.  Be careful when you play with this one. */

    position: relative;

    margin: auto;

    Width: 800px;

    height: 600px;

    text-align: left;

    top: 20px;

    background-image: url(images/homepage_new3.jpg);

    border: medium solid #336600;

    position: relative;

    }

    Edit the css for FBlogo to as below:

    {#FBlogo}

    position: absolute;

    left: 700px;

    top: 380px;

    Width: 91px;

    z-index: 1;

    text-align: center;

    }

    Edit the css for bodytext as below:

    {.bodytext}

    do-family: Verdana, Arial, Helvetica, without serif.

    do-size: 11px;

    line-height: 13px;

    margin: 0;

    padding: 0;

    }

  • How can I create spreadsheet with connection to a master spreadsheet?

    I created a main table and I need to copy this table, I need this table 2 are linked. How to do this?

    Hi Jean-Claude.

    My interpretation of your question:

    You have a master table.

    You want to create a second table (servant) with the same number of lines, the same number of columns, and the same data displayed in each pair of corresponding cells.

    You want the two linked tables so that as data is modified in a cell on the master, the change will occur also in the cell that is matched in the employee.

    Using numbers, it is possible, provided the tables are in the same document, and all copies is in the same direction.

    Here is a small example.

    First, select the table and reproduce them. This option preserves all the column width, row height, the fill color parameters and all other parameters of format that you have made the master.

    Option: Just add a new table with the same combination of header lines, columns of header or footer until.

    Move the duplicate to a position on the sheet where it does not cover all of the original.

    At this point, you have a second copy of the table, but the two tables are independent of each other.

    Change the name of the second table in the "servant" and make the same change in cell A1 (or any where you have the name of the table appears.

    In cell A2 of the second table, enter a =, and then click the cell in the first table. Click on the green check mark or press return to confirm entry.

    In cell B1 of the second table, enter a =, and then click the cell in the first table. Click on the green check mark or press return to confirm entry.

    In cell B2 of the second table, enter a =, and then click the cell in the first table. Click on the green check mark or press return to confirm entry.

    The three entries are necessary because the table has a header row and a column header. The next step can be executed through the border between rows/columns header cells and cells in the body of the table.

    Select cell A2 (single click) of the second table. In the border of the cell, you will see three small circles. Yellow to the center of the bottom and right edges are handles to fill. Use the mouse to grab the bottom and drag it until the end of the column.

    Select cell B1 and then drag the handle to fill on the right at the right end of the line 1.

    Select cell B2 and drag the handle to fill just right to the last column of the table. The trail of the background fill handle up to the last row of the table.

    You won't see any change in the tables, but you have now bound each cell in the table servant (except A1) to his companion in the Master table.

    Any change in the content of a cell in the Master immediately (on confirmation) change in th same servant table cell.

    Note that the changes made by a user in table servant will not have a change in the Master table.

    However, the data entered by the user in the table servant will replace the formula in this cell, breaking his connection with the cell matched in the Master table. Subsequently, Exchange in this cell in the master table has no effect on the table of servant.

    On the following tables, there have been five changes in the order shown:

    1. "Change" is entered, replacing C - 2 in master.
    2. Current date is entered, by replacing D - 3 in master.
    3. 'User input' is entered, replacement E-4 in servant.
    4. "Entry of the user" is entered, replacing F-4 in servant.
    5. "1005" is entered, by replacing E - 4 in master.

    Kind regards

    Barry

  • The table of hash of the dates

    Hello.  I have a table of hash on the dates and phone numbers (string/integer).  I need a loop through the hashtable and get the sum of the values for all the keys that fall between 2 dates.  Not sure how I'm going to address the issue.  What is an effective way?  I think something like what follows however not sure it's the right approach...

    Keys enumeration = theHashTable.keys ();

    Elements of the enumeration = theHashTable.elements ();

    Key of type string;

    Integer value;

    {while (Keys.hasMoreElements ())}

    key = (String) keys.nextElement ();

    value = (Integer) elements.nextElement ();

    somewhere / somehow thrown string date as long to compare/verify if this key is between a range of dates and, if so summarize values

    }

    Any suggestions on an efficient way to achieve this?

    For me, this is not a very large number and thus probably justifies no complications.

    I would design your data structure to optimize the use of the most active and then do all the rest by brute force.

    So if your use is going to be mainly the extraction of values between two dates, and then use a sorted vector, sorting manually if you think that it's easier and do a search sequential or same binary to find the values associated with a date specific.  If you're always looking for dates, then stick with the hash table and then enumerate over it to the value of a total range.

  • Create a temporary table using EXECUTE IMMEDIATE

    Hello

    I need to create a report more complex which must have three different queries. I use a determined IF clause that the query that uses the report, according to the parameters.

    I want to write the output to a csv file, so I created a PROCEDURE.

    The first package of the procedure has the three SQL and the IF clause in order to determine the query that the report uses and stores the query code in a variable (v_sql), which is passed to the PROCEDURE that needs to write to the output of the report.

    I tried to create a table with data from the request in order to make a LOOP and exit, something like this:

    WRITE_FILE (errBUFF of the PROCEDUREOUT VARCHAR2,
    retCODEOUT VARCHAR2,
    v_sqlIN VARCHAR2)

    IS

    ContorNUMBER;

    BEGIN

    EXECUTE IMMEDIATE v_sql;
    SLIDE G
    IS
    Select * from XXROR_REG_MF_TBL;
    --
    -initialization
    --
    retCode: = 0;
    errBUFF: = NULL;
    Contor: = 0;
    --
    -cursor
    --

    FOR X IN G
    LOOP
    APPS. FND_FILE.
    PUT_LINE)
    APPS. FND_FILE. OUTPUT,
    ....)

    I should mention that v_sql is something like:

    CREATE GLOBAL TEMPORARY TABLE ACEs (SELECT * of the double);

    I can't really do that, so I was wondering if you have any suggestions

    Thank you

    Claudiu

    Hello

    I don't think you need a table at all. You can set the cursor based on the SQL passed as parameter

    https://docs.Oracle.com/database/121/LNPLS/dynamic.htm#LNPLS629

    Concerning

    Marcus

  • Create a temporary table as select fails... Why?

    Hello, I have this simple stored procedure

    PROCEDURE prueba_cursor is
    BEGIN

    CREATE TEMPORARY TABLE global emp_tab ON COMMIT PRESERVE ROWS AS
    SELECT T.STATUS_CD IN THE T_CRES_FILES T;


    END prueba_cursor;

    I get the following error

    "PLS-00103: encountered the symbol"CREATE"when waiting for one of the following values:

    (begin case declare exit for goto if loop mod null pragma
    raise return select update while < ID >


    "

    What's not here?
    Thank you

    Xavi says:
    Hello, I have this simple stored procedure

    PROCEDURE prueba_cursor is
    BEGIN

    CREATE TEMPORARY TABLE global emp_tab ON COMMIT PRESERVE ROWS AS
    SELECT T.STATUS_CD IN THE T_CRES_FILES T;

    END prueba_cursor;

    I get the following error

    "PLS-00103: encountered the symbol"CREATE"when waiting for one of the following values:

    (begin case declare exit for goto if loop mod null pragma
    lift the back updated select everything with

    "

    What's not here?
    Thank you

    You can't put DDL statements directly into the PL/SQL like this. Why you wrap upward in a PL/SQL procedure anyway?

    Why not:

    CREATE GLOBAL TEMPORARY TABLE  emp_tab ON COMMIT PRESERVE ROWS AS
          SELECT T.STATUS_CD FROM T_CRES_FILES T;
    

    directly as SQL?

  • The currency exchange rate table

    How do I configure users to be able to only read the exchange rate table in the planning or Smartview? SmartView the intersection is at the highest level for all formats except the year, the period and the scenario. Or only the administrator will be able to see the exchange rate? Thank you for your time and help

    I donno how easy it is, but just a thought, create a form with a model member of all dimensions, except the scenario and the period...
    have a script that will copy the values of the dummy members for the dimension intersections of storage rates and execution level members to save the form.

    Thank you
    RAM Reddy

  • Planning 9.3.1 Exchange rate table

    Hi gurus,

    I have created table exchange rates and attached to the scenario planning 9.3.1 and I am able to run successful business rules. the consolidation at the level of the parents and Local to my base currency passes except the currency conversion. I checked in the planning of log file, this is the error I get, but I'm not able to find that is not the table exists. I thought because of this currency conversion does not occur. Has anyone in front of it? Please help me.


    Query failed: SQL_DELETE_EXPIRED_EXTERNAL_ACTIONS: [100]
    java.sql.SQLException: [Hyperion] [Oracle JDBC Driver] [Oracle] ORA-00942: table or view does not exist

    at hyperion.jdbc.base.BaseExceptions.createException (unknown Source)
    at hyperion.jdbc.base.BaseExceptions.getException (unknown Source)
    at hyperion.jdbc.oracle.OracleImplStatement.execute (unknown Source)
    at hyperion.jdbc.base.BaseStatement.commonExecute (unknown Source)
    at hyperion.jdbc.base.BaseStatement.executeUpdateInternal (unknown Source)
    at hyperion.jdbc.base.BasePreparedStatement.executeUpdate (unknown Source)
    at com.hyperion.planning.sql.HspSQLImpl.executeUpdate (unknown Source)
    at com.hyperion.planning.sql.HspSQLImpl.executeUpdate (unknown Source)
    at com.hyperion.planning.event.HspExtChangeHandler.actionPoller (unknown Source)
    at com.hyperion.planning.event.HspExtChangeHandler.run (unknown Source)
    Encountered error with connection to the base, you re-create the connections.
    Excetpion nested: java.sql.SQLException: [Hyperion] [Oracle JDBC Driver] [Oracle] ORA-00942: table or view does not exist

    Concerning
    PrakashV

    Documentation

    "Each application has a default currency specified when the application is created. When you specify the exchange rate tables, only the default currency and the currencies of the triangulation are available as a destination currency. You can enter the default source currency exchange rates or currencies of triangulation. »

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • How to create a second table containing the first?

    I have a table with data source. I would like to create a second table that feeds these data. I will use the second table for the filtered views, etc. I am currently copying a range of cells through, referring to table 1. However, if a new line is added to table 1, it does not table 2. How can I configure things so that any changes - including the new lines/columns would be automatically carried over to table 2?

    Table 2 cannot automatically grow the new rows or columns. If you want it to be completely 'automatic', your second table must be as large or larger than your first picture will be never. In other words, there need to additional rows and columns to allow growth. If is not bigger than 1 table, when you add rows or columns to the table 1, you must also manually add rows or columns to the table 2.  The problem is that all these lines/additional columns in table 2 will have formulas that are referred to non-existent rows/columns in table 1, which is a mistake. What you do next depends on what you do with table 2. If it is just for display of data and your existing formulas are all as = 1::A1 Table, you can change to = SIERREUR (array 1::A1, "") to get rid of the errors.  To hide all blank lines, you can set up a filter to show only the rows where column A is not a space (for example) character. There is no filter to hide additional columns, however.

  • How to make the exchange of data between 2 whole loop real-time

    Hello
    I have 2 while loop
    the 1st loop includes data acquisition program
    the 2nd loop includes control program
    --------------------------------------------------------------------------------------------------------------
    My question is how do the exchange of data between 2 whole loop real-time

    --------------------------------------------------------------------------------------------------------------
    I tried with the variable and direct wiring between the 2 local while loop
    It does not work (there is a delay)


  • help with table in spreadsheet string

    Hello

    I need assistance to format my 2D in a string table.

    I have a 2D DBL like this chart:

    and I want it in a format string like this "0.12 0, 1 0.34, 2 0.11.

    Line 0 pass 0 0 Col 1 Row line 1 Col 0 line 1 Col 1 line 2, column 0 line 2 Col 1... and so on

    Is this feasible with 'Table to a spreadsheet string' function or do I have to use a loop for format in this way?

    Thank you

    Ritesh

    Here are 2 ways to do it without loop.

    Ben64

    EDIT: just realized, you want a comma to separate lines, and replace the tab with a comma in solution 1. (2 will not work in this case)

Maybe you are looking for