Removal of the strings in a hash table

Hello to all PowerCLI'ers out there.  This is what, I hope, will be an easy one for you guys.

I built a hash named $hostInfo table that contains information about our VMHosts.  According to the information when displayed in a table format Name, UsedMemoryGB, TotalMemoryGB, FreeMemoryPct.

The release of "Format-Table" looks like this:

Name UsedMemoryGB TotalMemoryGB FreeMemoryPct
---------                                                               -----------------------             ------------------------                        -----------------------
us1esx0201.company.local 89.07421875 95.989414215087890625 92.79587700202785441462201182
us1esx0209.company.local 84.8193359375 95.989414215087890625 88.36321862267168020854706439
us1esx0211.company.local 83.681640625 95.989414215087890625 87.17798864517570982753322143
us1esx0205.company.local 83.3310546875 95.989414215087890625 86.81275468644519191613067240
us1esx0403.company.local 96.3408203125 111.989383697509765625 86.02674390344222204017427325
us1esx0401.company.local 95.689453125 111.989383697509765625 85.44511092539192491691602221
US1-vmhesx - p0515.company.local 81.6171875 95.989383697509765625 85.02730651672824441211219264
us1esx0303.company.local 95.1884765625 111.989383697509765625 84.99776802023479984310570319
US1-vmhesx - p0512.company.local 81.4462890625 95.9893798828125 84.84927099428367955541142883
us1esx0113.company.local 81.3212890625 95.98944091796875 84.71899438605549341860543489

Here is the code snippet that generates the hash table:

$hostInfo = get-VMHost |

Select name "

@{N = "UsedMemoryGB"; E={$_. MemoryUsageGB}} '

@{N = "TotalMemoryGB"; E={$_. MemoryTotalGB}} '

@{N = "FreeMemoryPct"; E={(($_. MemoryUsageGB / $_. {{(MemoryTotalGB) * 100)}} |

Sort-Object-descending - property 'FreeMemoryPct ' | Select - 10 first

Here is my challenge... I want to remove the '. '. company.local"of all entries in the"Name"column and only let the real host name.  How would I go about iterate the key 'Name' and deleting only this part of the chain?

Any help is appreciated as always!

-jSun311

You can create the table in the right format with just the name of the host if you change the second line of your script in:

Select @{N = "Name"; E={$_. Name.Split('.') [0]}},

If you want to change the variable $hostinfo, then you can use:

$NewHostinfo = $hostinfo | Select-Object - property @{N = "Name"; E={$_. Name.Split('.') [0]}}, UsedMemoryGB, TotalMemoryGB, FreeMemoryPct

Tags: VMware

Similar Questions

  • Put the string value in a table

    Hello

    Probably an easy question, but I am reading data of a RFID reader that returns a string value of 12 bytes. Whenever a RFID reads, I want the tag to be inserted in a string table on the front panel. So, basically, a newspaper of the each tag [read-> Insert row 0] then [read-> Insert level 1] and so on. I work RFID reader, I don't know how to put the string in the table.

    I'm not sure of the steps necessary to achieve control of the table (or if the table control is the right thing to use).

    Any help would be greatly appreciated. Thank you.


  • convert the string into individual components table

    Hello Experts,

    I would like to display an array of strings in a display of text/string. for example:

    My array of strings is:

    ['I', 'L', 'O', 'V', 'E', 'L', 'A', 'B', 'V', 'I', 'E', 'W'], and I want to show this picture as I LOVE LABVIEW in an indicator of the string and not an indicator array.

    How do I do that? I tried flatten to sting, but it added a lot of zero to the channel indicator, and the display is not only correct appearance.

    I hope my question makes sense.

    The functions of concatenate strings will do exactly what you want.

  • Writes the string data in a table

    Hello

    I am facing a problem in writing the data in the table. Here is its description:

    1. I created a code that reads the URL from OPC.server.

    2. I need to display it in a table. Since the number of URL is known, I defined the rows in the Table.

    3 but am not able to display these URLS in the table.

    This problem can be simply put on 'how to write string in the table. property node can be used and if so, what assets can be used?

    I'm still a beginner in this... so would like help of all my colleagues LabVIEWers there

    Thank you best regards &,.

    Nadège.

    This is a base update. The initialize array must be specified as a number greater than your maximum number of URLS.

  • Function to remove stopwords from string

    Hello

    I would use a very effective feature that eliminates all the empty words of a given string (array of empty words: select distinct spw_word from ctxsys.ctx_stopwords).
    Any help will be much appreciated.

    Kind regards
    MR. R.

    Hello

    Seems good! I would suggest a few changes in the body:

    BEGIN
        mystr := ' ' || str || ' ' ;               -- See note 1
    
        FOR cr IN c
        LOOP
            mystr := REPLACE ( mystr
                           , ' ' || cr.x || ' '
                           , ' '                    -- See note 2
                    );
        END LOOP;                              -- See note 3
    
        mystr := TRIM ( REGEXP_REPLACE ( mystr          -- See notes 1 and 2
                                      , ' {2,}'     -- 2 or more spaces
                           , ' '     -- 1 space
                           )
                 );
        RETURN  mystr;
    END f_replace_stopword;
    

    Notes:
    (1) not to clutter the code with a lot of unnecessary trimming. Before entering the loop, you must make sure that mystr begins and ends with a space, because of the problem of 'mother is in chemotherapy' as mentioned William. However, if the chain has already spaces here, is not what anyone let them hurt. The same goes for storage mystr each pass through the loop. The amount of resources, it's waste is small (if it's to lose, anyway), but I'm more concerned with having unnecessary code distract people from the real business of the function. All the extra spaces can be picked up at the end, after leaving the loop.

    (2) so-called "FUBAR" is one of the empty words that you remove, and the string contains 'A FUBAR B. If you remove just the empty word (with its spaces added), which will leave you with "AB". I guess you want 'A B', with a space between what were originally two different words. This would be particularly important if the empty word "AB" happened to appear later in the list.
    This can cause multiple consecutive spaces being left in mystr; additional spaces can be deleted once the loop is completed.

    (3) If you do not use an OPEN statement to open the cursor, then you don't need a statement CLOSE to close. Leaving a LOOP FOR cursor automatically closes the cursor.

  • Select the string table drop-down list box.

    Hi all

    I want to select the combo box list based on a string in the entry, I don't know how to do this. I have a drop-down list box and the value comes from a database, what I want to do is I want to change the value of the selected box based on the existing value in the database drop-down list. for example, A, B, C D I strings in the drop-down list box, and then in my database, I have a field with the string C, I want to change the C to A. I can't enter the value of C in a string format, but I don't know how to be the first position of the drop-down list box in so the order of channels combo box will be C, A, B, d., the value of C

    Thank you

    Then just write a new array of strings, with the elements of the new agenda, to the "[] strings" - property.

    Either you must code something that allows you to create an array of strings with the elements in the order that you want them to be. If there is a reorganization only, you could do something like:

    -Get the array of strings [] from the drop-down list using a property node box.

    -Find the position of the element you want to place first and use "delete from table", which returns the new array and the element removed.

    -Build a new table 1 d of the deleted item and table remaining. Move to the second combobox Strings [] property of a node property.

  • ListField using the hash table

    Hi guys, new here so please, be gentle.

    I was wondering if there is way to a ListField (or something similar) but using a hash instead of a vector table. I searched through the forums without success. And if it is would it be possible to display the incredible list. (List in the hash table and sort by alphabetical order, via the keys)

    The hash table structure K = String (name of player), V = object reader.

    If this can be done using a hash table, is there a way to do this using a vector. So that I could search the data structure for a players name and return the object.

    Sorry if it's confusing or vague. I'm not not used to describe my problems!

    Thank you very much for the help.

    You can also move forward and persist in the hash table, and then build an index using a few stores of SimpleSortingVector who keys in order.

    There are a lot of options... you just need to decide which is best for you.

  • Defeated by tri-objet in the hash Table

    Hi guys, I need someone who is smarter than me to help please, suck for 3 days now.

    The Script below uses a CSV file as a database to pull total VMs in my vcenter in a bar chart, showing the trend upward. . My boss wants it as soon as possible.

    I can not however the $HT variable to sort by date (sorting and tri-objet doesn't seem to work, sort of NAME or WEEK)

    Need help please, I'm stumped.

    Note, tips cut off when I pasted it, like}'s and impossible.

    # Created by ELMO

    Add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue

    $Date = Get-Date -Format yyyy/MM/dd

    $VCRUN = ' Ma Blanked to vCenter '

    $Report = @()

    $USER = "Ma Blanked user"

    $PWD = "Ma Blanked on pwd"

    Write-Host ' Connection to $VCRUN"" "".

    VIserver disconnect -Confirm:$false

    Se connect-VIServer -Server $VCRUN -User $USER -Password $PWD -wa 0

    $VMsON = Get-VM | Where-Object {$_. PowerState -eq "PoweredOn"}

    $VMsTotal = $VMsON. County

       $Row = "" | Select Week, VMsTotal

       $Row . Week = $Date

       $Row . VMsTotal = $VMsTotal

       $Report += $Row

       $ReportView = $Report | Export-Csv -Path C:\PS\Output\VMTrendDB.csv -Append -NoTypeInformation #-Append the data at the bottom of the existing file

    $MyData = Import-Csv C:\PS\Output\VMTrendDB.csv | Select-Object week ,VMsTotal

    $HT = @{}

    foreach ($Data in $MyData) {

    $HT. Add($Data. Week , $Data . VMsTotal)

    }

    $HT = $HT | Tri # read on the Technet site as tri-objet does not change the actual table, but only the output. Thus uses only sort. $HT = HT Triedd | Sort = Name object AND object week type, they do not change my picture on the order of dates

     

    Function Créer-Chart() {

    Param(

      [String] $ChartType ,

    [String]$ChartTitle,

      [String] $FileName ,

    [,String]$XAxisName,

      [String] $YAxisName ,

    [Int]$ChartWidth,

    [Int]$ChartHeight,

    [HashTable]$DataHashTable

    [Sub] [Reflection.Assembly]:LoadWithPartialName ("System.Windows.Forms"( )

    [Sub] [Reflection.Assembly]:LoadWithPartialName ('System.Windows.Forms.DataVisualization'( )

    #Create our graphic object

    $Chart = new-object System.Windows.Forms.DataVisualization.Charting.Chart

    $Chart. Width = $ChartWidth

    $Chart. Height = $ChartHeight

    $Chart. Left = 10

    $Chart. Top = 10

    #Create a chartarea to profit and add this to the table

    $ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea

    $Chart. ChartAreas . Add ($ChartArea)

    [void]$Chart. Series . Add("Data")

    $Chart. ChartAreas [0]. AxisX . Interval of = '1' #Set to 1 (default is auto) and allows all the values of the X axis appears correctly

    $Chart. ChartAreas [0]. AxisX . IsLabelAutoFit = $false;

    $Chart. ChartAreas [0]. AxisX . LabelStyle . Angle = "-45"

    #Add real data to our table

    $Chart. Series ["Data"]. Points . DataBindXY ($DataHashTable. ) Key , $DataHashTable. Values)

    if (($ChartType -eq "Pie") -or ($ChartType -eq "pie")) {

    $ChartArea. AxisX . Title = $XAxisName

    $ChartArea. AxisY . Title = $YAxisName

    $Chart. Series ["Data"]. ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]:Pie

    $Chart. Series ['Data'] ['PieLabelStyle'] = "Outside"

    $Chart. Series [« Data »] [« PieLineColor »] = "Black"

    $Chart. Series ['Data'] ['PieDrawingStyle'] = "Concave"

    ($Chart. Series ["Data"]. Points . FindMaxByValue()) ["Exploded"] = $true

    $Chart. Series ["Data"]. Label = ' #VALX = #VALY\n ' # make a X & Y Label of the data in the (useful for Pie chart) plot area (display the axis labels, use: Y = # ControlChars.LF = #VALX)

    elseif (($ChartType -eq "Bar") -or ($ChartType -eq "bar")) {

    #$Chart.Series ["Data"]. Sort ([System.Windows.Forms.DataVisualization.Charting.PointSortOrder]: descendant, "Y")

    $ChartArea. AxisX . Title = $XAxisName

    $ChartArea. AxisY . Title = $YAxisName

    # Find point with max/min values and change color

    $maxValuePoint = $Chart. Series ["Data"]. Points . FindMaxByValue()

    $maxValuePoint. Color = [System.Drawing.Color]:Red

    $minValuePoint = $Chart. Series ["Data"]. Points . FindMinByValue()

    $minValuePoint. Color = [System.Drawing.Color]:Green

    # make the bars in the 3d cylinders

    $Chart. Series [« Data »] [« DrawingStyle »] = "Cylinder"

    $Chart. Series ["Data"]. Label = '#VALY' # Label Y to the data in the plot (useful for the diagram bar) area

    else {

    Write-Host "no Chart Type has been defined. Try again and enter Pie or Bar for the ChartType parameter. The table will be created in the form of standard bar graphic chart for now. " -ForegroundColor Cyan

     

    #Set the title of the chart for the date and time

    $Title = new System.Windows.Forms.DataVisualization.Charting.Title

    $Chart. Titles . Add($Title)

    $Chart. Titles [0]. Text = $ChartTitle

    Graphic to a file #Save

    $FullPath = ($FileName + ".png")

    $Chart. SaveImage ($FullPath 'png'( )

    Write-Host ' saved chart in $FullPath"" " -ForegroundColor Green .

    back $FullPath

     

    Create Chart -ChartType bar ChartTitle - "machines virtual VMware in DC1" -FileName C:\inetpub\ELMO\Graphic\VMsTrendChart -XAxisName 'Date' -YAxisName 'number of VMs' -ChartWidth 800 -ChartHeight 800 -DataHashTable $HT

    All by setting the variable $HT, you define it as a Table of hash, sort or Sort-Object does not work on hash Tables, they work on arrays. Your definition is

    $HT = @ {}

    Use $HT = @)

    Instead, which will create a table and you would be able to define objects and then use the Sort-Object there. With Hash Tables, since they hold any objects you can not sort using Sort-Object.

  • Possible to develop a chain of the variable inside a literal hash table?

    Attempt to run together-qadcomputer

    together-qadcomputer $adserver - ObjectAttributes @{$VARIABLENAME}

    When I do that - I get the error: Missing '=' operator after the literal hash key.


    The string variable contains the equivalent of the data pairs = of value that works when the entries manually.

    $VARIABLENAME = "' edsvaVar1"= $valeur1;"edsvaVar2"= $valeur2;"edsvaVar3'= $Value3 '.

    When I read the $VARIABLENAME, I see the values that I expect.  I want the same effect of in the literal hash required for the cmdlet set-qadcomputer when you use the @ {BOM} that supports several pairs of value.

    Possible?

    ARS 6.9

    There are two ways to do this.  Add command-line string and then use invoke-expression not at my peak, I think it is the correct command, I used this in a prior cultures and when just debugging print any line to ensure that the expansion works well.  The other option is to use a hash table to store the settings of command and a third, I just thought that everything is instead of create a variable string place the attribute pairs in a table, I'm sure it will work also.  If you can only use a string and then use the invoke-expression cmdlet.

  • How to convert the string with numbers in the table of Boolean 2D

    Hello

    I have input a string with comma separated numbers 1,192 (starting at 1).

    This string must be converted to a table 2D-boolean. Each number that appears should be true, not true rest.

    The 2D table consists of 4 times of 0.47 Boolean values.

    1.48--> [0.47] numbers [0]
    49.96--> [0.47] numbers [1]
    Numbers 97.144--> [0.47] [2]
    145.192--> [0.47] numbers [3]

    If a '1, 49, 97 145' input string put all [0] [0.3] true.

    How can it be easy/fast resolved?

    Thanks for help

    Break the string of numbers in a table of numbers.  (Spreasheet String to Array).

    In a loop For, index with each issue of this table.  Use in the range and Coerce to see if it is in the range of numbers.  (You can put this in a loop For as auto good indexing through the ranges).  If it's in the range, then use subset replace table to activate the corresponding item in a real.  If this is not the case, do nothing.  Maintain the table of Boolean in a shift register.

    Repeat this step for each number in your table.

    (What is a class assignment?)

  • Save and load the string table

    Hello

    is possible except an array of channel with multiple line of text file and load new file to table with the same size of array?

    Because when I use the code in the picture, initialized array is 3 x 3 but after save and load file is table 5 x 3.

    If is an option how to save this table in the file into 3 x 3 table and charge back of file as a 3 x 3 table?

    Thank your for any suggestion,.

    Petr

    Your code is loaded in 5 x 3 is because two of your cells have newline characters (\n). The reading of the worksheet VI use return or line break characters and your delimiter to figure out how to split the string into an array.

    A solution might be to replace all characters from end of line with something else, and then reinsert it after reading of the worksheet.

    It can do what you want, even if it's a bit bulky. It's a little confusing if you don't understand "------" string formatting, but it essntially replaces all '\r' and '\n' with '\\r' and '\\n', including the conversion of the worksheet does not read as an end of line character.

  • remove the string in double paragraph

    Hi, I wandered if someone had the best way to search for a string and delete the repeated subsections.

    For example, the input string may look like:

    T2, T2, T3, T6

    but I want to delete one of the T2 repeated, so the output would be:

    T2, T3, T6

    Note that the input string can be any length and a multiple of 4. I went through all the string functions and find nothing to match what I'm asking. I tried to use "String subset" in a wired loop in an output table.

    Any help in the right direction would be appreciated!

    Here's a handy dandy little tool that does just that.  The strings must be delimited by commas.  It is in LV2009.  If you do not, save the file and send it to the thread Downconvert VI ask.

  • Returns a copy of the hash table

    I have problems by returning a copy of a hash that is normally stored in the persistent store table.

    final class SyncCentres {
        private static Hashtable syncCentres;
        private static PersistentObject persist;
        private static final long ID=0xdfeab99e040a223aL;
    
        static{
            persist=PersistentStore.getPersistentObject(ID);
            syncCentres=(Hashtable)persist.getContents();
            synchronized(persist){
                if(syncCentres==null){
                    syncCentres=new Hashtable(4);
                    persist.setContents(syncCentres);
                    persist.commit();
                }
            }
        }
    
        static Hashtable getSyncCentres(){
            return syncCentres;
        }
    
    } // Class
    

    When I get the hash table in another class by using the static method.

    Hashtable hash=SyncCentres.getSyncCentres();
    

    It turns out that it is not a copy. Change the hash variable will edit the SyncCentres class as well. Is this normal? How can I get a copy of it?

    Java, copy and pass the reference by value, not the object.
    See
    http://www.Yoda.arachsys.com/Java/passing.html
    or
    http://www.JavaWorld.com/JavaWorld/javaqa/2000-05/03-QA-0526-pass.html
    If you want a true copy of the hash table you need to clone and each of its objects.
    You can also copy all objects to a new hash table, but these are always references to the same objects as in the first hash table.

  • Replace the string value of table

    with cte as)

    Select val '123', 'abwec' double val1

    Union of all the

    Select "456" val, "mowerw" double val1

    Union of all the

    Select val '709', 'wkwere' double val1

    Union of all the

    Select val '078', 'awerwewerwreq' double val1

    )

    Select * from cte;

    -incoming string

    "asdasd123ewrwer@87w8eopiu456werwer@asdwer709@ewrwerewrwqqwezxder078 @..."

    need to replace like 'abwec' 123 and 456 as "mowerw" and 709 as wkwere and 078 as 'awerwewerwreq '.

    How to replace the string value of the string

    I'm going to the table which will have mapping information I need to see the incoming string and replace the appropriate value of the val to val1

    something like

    Of

    "asdasd123456werwer@asdwer709@ewrwerewrwqqwezxder078ewrwer@87w8eopiu @..."

    TO

    "asdasdabwecewrwer@87w8eopiumowerwwerwer@asdwerwkwere@ewrwerewrwqqwezxderawerwewerwreq@..."

    By using the TYPE clause.

    with cte as

    (

    Select val '123', 'abwec' double val1

    Union of all the

    Select "456" val, "mowerw" double val1

    Union of all the

    Select val '709', 'wkwere' double val1

    Union of all the

    Select val '078', 'awerwewerwreq' double val1

    ),

    input_tbl

    as

    (

    Select "asdasd123ewrwer@87w8eopiu456werwer@asdwer709@ewrwerewrwqqwezxder078 @..." input_str

    of the double

    )

    Select max (input_str) Dungeon (first order by desc NWR dense_rank) input_str

    de)

    Select rno, input_str

    de)

    Select rownum NWR

    val

    val1

    input_str

    count (*) over() cnt

    from cte

    Cross

    Join input_tbl

    )

    model

    dimension (NWR)

    measures (val, val1, cnt, CAST (input_str AS VARCHAR2 (4000)) input_str)

    (

    input_str [any] = replace (nvl (input_str [cv () - 1], input_str [cv ()]), val [cv ()], val1 [cv ()])

    )

    )

  • Remove the performance of a large table or several small tables.

    I have a table with 30 million lines, that is used in a statistic application developed in home treatment.

    In the process, there is an application that will scan old records and then remove them from the database.

    I'm looking for a way to improve it, and I am currently faced with alternatives:

    Option #1
    Separate the old records into several smaller tables, and then run several copies of the application, a single instance of the application by the smaller table.

    Option #2
    Use additional criteria to when choosing the rows of the table (which would be indexed on), an execution mulltiple of copies of the application based on the criteria.

    From a logistical point of view, I'd prefer Option #2, my only concern with him is what's performance comparrison between:

    50 processes Delete form 50 small individual tables with 100,000 rows in each
    vs
    50 to a table with more than 30 million lines removal process

    Anyone has any experience on a preview?

    We use an instance of Oracle 9i, no partitioning.

    Unfortunately I don't have a lot of control in the application or make major changes to Oracle.

    940507 wrote:
    It redundant seams, one of the reasons why I prefer Option 2, using additional criteria...

    I just need to make sure that when 20 process attempts to remove it from the same table with 30 + million lines, the contetion on the updating of the table, index... will not introduce a point of suffocation.

    This can vary widely based on the distribution of data and model of data access. Oracle accesses data in blocks, so if someone updates an another line of the block while you delete, you could get a transaction wait. For playback from your deletion, Oracle is good, not blocking, but compromise can be a lot of waiting. If your data in the table such as two of your processes to remove from the same block, you could come back here crying on the performance and have people laugh design.

    Rather than the mud things with more java spawning process, you may need to perform these deletions by a single stored procedure with very specific criteria. Then, rather that dealing with the issues of contention, you serialize everything to go as soon as possible and reduce to a minimum the block copy and cancel demand to keep multiuser. Oracle is biased in favor of adding data instead of delete, add will always be potentially more fast-able.

    Think about this: http://jonathanlewis.wordpress.com/2011/04/19/more-cr/

Maybe you are looking for