PowerCLI script retrieve vmname based on the value of the custom field

I want to retrieve a set of virtual machine based on a custom attribute names.  I have a custom field called alert level and I want to list only servers with an alert level of 4 so that I can automatically turn them off during a power failure.

That's what I have so far:

Get - VM | Select Name -ExpandProperty CustomFields | {$_.key -eq "Alert Level"} | {$_.value -eq 4}

This seems to me the namem, field and value but all I want is the name.

Any ideas?

Try this

Get - VM | where {$_.} {CustomFields ["warning level" ""]- eq 4} | Select the name of


Tags: VMware

Similar Questions

  • Automate snapshots based on the custom field

    I am a newbie to scripting and can't creating a Powershell script that will automatically create snapsht based on a custom attribute that is specified on the virtual computer. I got so far:

    Get - VM | Select the custom name fields - ExpandProperty | Where {$_.value - eq "takesnapshot"} | Select name

    This gives me a list of virtual machine names that have the specified "takesnapshot" custom field, however, I don't know how to use the output with the Get - VM | New snapshot command to create a new snapshot. Any help would be appreciated.

    OK, the key is "Ministry" and the value is "instant".

    With the attached line, you should get in the market.

    Your test had a few typos: it should be $_ and you should leave out the test to white before the brackets.

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • How to retrieve the value of a custom field

    Hello @all.

    In my vCenter, I created a custom field 'email '. The value of this field is set to the e-mail address of the operator of that belongs to a virtual machine.

    I would like to retrieve these values in a perl script. But I have found a method to set the values of the custom fields. For example:

    $CustomFieldsManager -> SetField(entity => $_, key=> $emailKey, value => "[email protected]");
    

    What should I do to retrieve the value of the $emailKey key? Could someone provide a quick and dirty-snippet, please?

    Best regards

    Trondesson

    of course, in this discussion https://communities.vmware.com/message/1512863#1512863 you can see how it's done

  • Question regarding setExtent and getPreferredWidth for the custom field

    I am trying to understand the difference between getPreferredWidth and setExtent, which relate to the width of a custom field.

    I create a field that may be greater than the width of the screen. The field is made up of cells (for example columns and lines or cells, such as a table). The cells contain text, shapes, lines, color, etc. When I display the field I only paint the visible columns on the screen and allow the user to use the trackball to accomplish the columns out of the screen.

    At present, getPreferredWidth returns the total width of the field without all the empty columns, is longer than the width of the screen. I use the same value in setExtent for width. GetPreferredWidth must return the size of the field that is painted on the screen - the total width less the width of the columns out of the screen? I have the same question about setExtent - width either in total, longer than the screen width or the width of the part of the field that is painted on the screen?

    If I use the width of what is painted on the screen or the other of these methods, then the width changes when the user scrolls through the field. As the user scrolls, I calculate the number of columns will agree to a width of the screen and paint these columns. Is it a problem to have the PreferredWidth and the setExtent change width? I read that setExtent is called only when the Manager sets this field, so that the changes will not be recognized.

    It seems to work in two ways in a few simple tests, but I was just curious as the value of width that is right.

    Thank you!

    Mark

    When a field has changed in a way that requires the update of the screen (for example, after scrolling offset changes), simply call invalidate() from this area. That will eventually lead to paint (Graphics) for the field. At this point, you return the update field. (If only part of a field - as a single cell - needs to be updated, there invalidate() versions that accept arguments where, for efficiency, you can limit the update for just this part.)

    If I understand your needs, you can achieve the effect desired in the paint method. You can use the current dimensions of the field, the cutting of the graphics area, and your internal roll compensates to decide what to paint and what to delete. Let your custom field leave white space where you decide of doesn't make is not part of a cell. There is no need to change the scope of the field.

    If you go about it by changing the dimensions of the field, and then you ask the system to play much more work he has to do. If the custom field is the only field on the screen, it won't make much difference in the behavior (although there may be performance). With more than one field, it can be weird effects. For example, suppose that your custom field is one of several fields in a HorizontalFieldManager and you change the field width. When the HorizontalFieldManager recalculates its own layout, it will change the horizontal position of the fields to the right. The effect on the user, I think, would be really confusing: as the custom field parade, parties to the right of the screen could bounce left and right as the changed width field. I can't imagine that's what you want.

    Here's another way to think about this: absent some bit of style, your custom field would prefer be exactly wide and high enough to show all without scrolling. So the width and height would be based on adding the appropriate cell widths and heights, regardless of what actually is on the display. (It's also a long time that you do not have something fanciful.) If the optimum height is a function of the width available - as with sheathed on the line of text - you would implement this logic in the layout method. You then have no use for autonomous preferred width and height).

  • Two sliders in the custom field definition

    Hi guys,.

    First of all, I want to thank all those who helped me to this day. This forum has been essential for blackberry dev work I do, and I would be screwed without you guys. That being said, I'm having a problem. I install a custom like this text entry field.

    (1) creates a vertical field Manager, assigned a background and resized image with setExtent(). (works fine)

    (2) created a new type of field and inserted in the vertical field Manager to make native look (almost works)

    The problem I have is that two sliders are appearing. Cursor #2 is dynamically updated as it should be, but the #1 cursor seems to be a "flawed slider. Please see the image below for details.

    The custom field is defined using the following code. If I remove the custom field, or cursors comes, so I am positive that it is the source of the problem.

        public class JustifiedEditField extends HorizontalFieldManager implements FieldChangeListener {
            BasicEditField ef;
    
            public JustifiedEditField(long style) {
                super(USE_ALL_WIDTH);
                ef = new BasicEditField(style) {
    
                    protected void onDisplay() {
                        setPosition(10, 17);
                        update(0);
                        //invalidate();
                    }
    
                    protected void update(int d) {
                        super.update(d);
                        setPosition(10, 17);
                        //invalidate();
                    }
    
                    protected void paint(Graphics graphics) {
                        graphics.setColor(Color.WHITE);
                        getFocusRect(new XYRect());
                        drawFocus(graphics, true);
                        super.paint(graphics);
                    }
    
                    protected void onUnfocus() {
                        invalidate();
                    }
    
                    protected void onFocus(int direction) {
                        invalidate();
                    }
    
                    /**
                     * Intercepts ESCAPE key.
                     * @see net.rim.device.api.ui.component.TextField#keyChar(char,int,int)
                     */
                    protected boolean keyChar(char ch, int status, int time) {
                        switch(ch) {
                            case Characters.ESCAPE:
                                // Clear keyword.
                                if(super.getTextLength() > 0)
                                {
                                    setText("");
                                    return true;
                                }
                        }
                        return super.keyChar(ch, status, time);
                    }
                };
                add(ef);
            }
    
            protected void sublayout(int width, int height) {
                super.sublayout(width, height);
                setExtent(width, 57);
            }
    
            public BasicEditField getEditField() {
                return ef;
            }
    
            public String getText() {
                return ef.getText();
            }
    
            public void setText(String value) {
                ef.setText(value);
                invalidate();
            }
    
            public void setChangeListener(FieldChangeListener changer ){
                ef.setChangeListener(changer);
            }
    
            public void fieldChanged(Field field, int context) {
                invalidate();
            }
        }
    

    I am totally stuck on this issue, any help would be really appreciated. TIA!

    I came up with an alternative solution. It turns out that I can use a transparent border to set the offsets to where the edit field must be located within the input Manager; thus eliminating the need to use setPosition.

  • Part of the cursor remains in the custom field

    Hello, guys!

    I have a problem.

    In the custom field that extends EditField, I want to draw in the text and the image and draw an appropriate in the cursor position. Then, we thought it would only calculate in advance of the police and the width of the image in the paint method to display the text and image and to the similar development and I tried. However, the cursor drawing is wrong. When the cursor moves from right to left, a part of the slider to the position immediately before the rest.

    Y at - it a good solution?

    JDE component package: 4.6.0

    I solved by myself.

    'FocusChangeListener' is mounted with EditField. And "invalidate()" has been called in the method "focusChanged().

    It became a great result for me.

    Thank you.

  • How long does it take for the custom field created in SFDC appears in the list of field mapping?

    How long does it take for the custom field created in SFDC appears in the list of field mapping? I hit the refresh field button, but it does not appear after 5 min. I just need to have patience?

    I had the same problem yesterday, I think it took about 10-15 minutes to appear.

  • PowerCLI script start vm and check the boot

    Hello

    I try to do a powercli script to start the virtual machine and check when the (windows) operating system is completely open and ready.

    How can I do?

    Maybe this helps...

    Start-VM - VM - runAsync

    $vm = get - vm

    Start-Sleep - seconds 20;

    $vm | Get-VMQuestion | Game-VMQuestion - version - confirm: $false;

    do

    {

    Start-Sleep - seconds 5;

    $toolsStatus = $vm.extensionData.Guest.ToolsStatus;

    } While ($toolsStatus - not "toolsOK");

  • PowerCLI script - new virtual machine of the model

    Hi all

    I am very new to power CLI scripting, and these days, that I read a lot of help to automate the creation of a new virtual machine based on the model of the virtual machine.  Script that is not that hard, even location new virtual machine on a particular data and in a particular resource pool store is not difficult.  For this I came up with this very basic script/command:

    "New-VM - ResourcePool < resource_pool > - < folder_name > location - Datastore < datastore_name > - name < VM_name > - < template_name >"model

    However, I came across some problems that I can't find information in help or in the forums.  Problem with the above command is VM will be created in the pool of appropriate resources and file as long as they are unique, but if there are multiple instances of resource pool or a folder with the same name as the script spits out a mannequin.

    So for example if I want to create a new virtual machine to the location following Data_Centre = > RootFolder1 = > SubFolder1 = > SubFolder2 and SubFolder2 name is unique that no problem, the virtual machine is created at this location.  However, if the SubFolder2 exists in Data_Centre = > RootFolder2 = > SubFolder1 as well as the virtual machine is created in the folder root of the location of the model.  For example, if the model is in "DC = > Folder1 = > Subfolder1 = > Subfolder2 ' the virtual machine will be created in the folder Folder1

    Any suggestions on how to ensure that the virtual machine is created in the desired folder/location as well as a list of resources?  In my view, there are really smart guys here and I suspect that this issue would not be a problem at all.  Any help would be appreciated.

    See you soon

    It is not a matter of following the right path.

    You can use the location setting to get the exact folder you want. For example

    $dc = get-data center-name DC1

    $folder = get-file-name Folder1-location $dc

    $subfolder = get-file-name Folder2-location $Folder1

    or

    $dc = get-data center-name DC1

    $subfolder = get-file-name Folder2-location $dc

    You will need to find a "place" in the path to your destination folder where it will be unique.

  • How to generate a sql script that is based on the structure of the table

    I want to generate a sql script that is based on a table structure.

    For example:

    If the table is:

    CID id c_value
    -----------------------------
    1 1 zz
    2 1 yy
    3 2 zz
    4 2 xx
    5 3 ss
    6 tt 3


    The expected output is:

    WITH
    CHILD_tab like)
    SELECT 1 cid, 1 id, 'zz' c_value of all the double union
    SELECT 2 cid, 1 id, 'yy' c_value of all the double union
    SELECT 3 cid, 2 id, 'zz' c_value of all the double union
    SELECT 4 cid, 2 id, 'xx' c_value of all the double union
    SELECT 5 cid, 3 id, 'ss' c_value of all the double union
    SELECT 6 cid, 3 id, 'tt' double c_value)


    11.1.0.7.0 release

    I do a lot of XML these days (maybe too well) so here is a solution involving XQuery.
    We pass a query string and it generates a CLOB containing the WITH clause:

    SELECT DBMS_XMLGEN.Convert(
    XMLQuery(
    q'[concat(
    "WITH t AS (
    ",
    string-join(
     for $i in /ROWSET/ROW
     return concat( " SELECT ",
                    string-join($i/*/concat("'",ora:replace(text(),"'","''"),"' ",local-name()),", "),
                    " FROM dual" ),
    " UNION ALL
    "
    ),
    "
    )")]'
    passing dbms_xmlgen.getXMLType('SELECT * FROM scott.emp')
    returning content
    ).getClobVal(), 1) AS WITH_CLAUSE
    FROM dual;
    
    WITH_CLAUSE
    --------------------------------------------------------------------------------
    WITH t AS (
     SELECT '7369' EMPNO, 'SMITH' ENAME, 'CLERK' JOB, '7902' MGR, '17/12/80' HIREDATE, '800' SAL, '20' DEPTNO FROM dual UNION ALL
     SELECT '7499' EMPNO, 'ALLEN' ENAME, 'SALESMAN' JOB, '7698' MGR, '20/02/81' HIREDATE, '1600' SAL, '300' COMM, '30' DEPTNO FROM dual UNION ALL
     SELECT '7521' EMPNO, 'WARD' ENAME, 'SALESMAN' JOB, '7698' MGR, '22/02/81' HIREDATE, '1250' SAL, '500' COMM, '30' DEPTNO FROM dual UNION ALL
     SELECT '7566' EMPNO, 'JONES' ENAME, 'MANAGER' JOB, '7839' MGR, '02/04/81' HIREDATE, '2975' SAL, '20' DEPTNO FROM dual UNION ALL
     SELECT '7654' EMPNO, 'MARTIN' ENAME, 'SALESMAN' JOB, '7698' MGR, '28/09/81' HIREDATE, '1250' SAL, '1400' COMM, '30' DEPTNO FROM dual UNION ALL
     SELECT '7698' EMPNO, 'BLAKE' ENAME, 'MANAGER' JOB, '7839' MGR, '01/05/81' HIREDATE, '2850' SAL, '30' DEPTNO FROM dual UNION ALL
     SELECT '7782' EMPNO, 'CLARK' ENAME, 'MANAGER' JOB, '7839' MGR, '09/06/81' HIREDATE, '2450' SAL, '10' DEPTNO FROM dual UNION ALL
     SELECT '7788' EMPNO, 'SCOTT' ENAME, 'ANALYST' JOB, '7566' MGR, '19/04/87' HIREDATE, '3000' SAL, '20' DEPTNO FROM dual UNION ALL
     SELECT '7839' EMPNO, 'KING' ENAME, 'PRESIDENT' JOB, '17/11/81' HIREDATE, '5000' SAL, '10' DEPTNO FROM dual UNION ALL
     SELECT '7844' EMPNO, 'TURNER' ENAME, 'SALESMAN' JOB, '7698' MGR, '08/09/81' HIREDATE, '1500' SAL, '0' COMM, '30' DEPTNO FROM dual UNION ALL
     SELECT '7876' EMPNO, 'ADAMS' ENAME, 'CLERK' JOB, '7788' MGR, '23/05/87' HIREDATE, '1100' SAL, '20' DEPTNO FROM dual UNION ALL
     SELECT '7900' EMPNO, 'JAMES' ENAME, 'CLERK' JOB, '7698' MGR, '03/12/81' HIREDATE, '950' SAL, '30' DEPTNO FROM dual UNION ALL
     SELECT '7902' EMPNO, 'FORD' ENAME, 'ANALYST' JOB, '7566' MGR, '03/12/81' HIREDATE, '3000' SAL, '20' DEPTNO FROM dual UNION ALL
     SELECT '7934' EMPNO, 'MILLER' ENAME, 'CLERK' JOB, '7782' MGR, '23/01/82' HIREDATE, '1300' SAL, '10' DEPTNO FROM dual
    )
    

    It may be useful for small datasets only because we reached quickly ORA-01706.

  • The use of javascript to save a pdf file in a different directory and generating a new file based on the form fields in the document name.

    I built the following script to create a submit button that will automatically save the document in a different directory on my computer. It will also use data form 'customer' field and 'date' to generate the file name. I printed the myPath variable, and it seems that he printed the correct string. I get the following error:

    TypeError: redeclaration of const path

    any help would be appreciated.

    var customer = this.getField("Customer").value;

    var date = this.getField("Date").value;

    var path = "C:/users/lead/My Documents/Test / '.

    Reg = date.match(/(\d+)\/(\d+)\/(\d+)/ var);

    var myPath = "C:/users/lead/My Documents/Test /" client + '_' + reg [1] + "." + reg [2] + "." +

    Reg [3] + ".pdf";

    this.saveAs (myPath);

    Thank you. It turns out that simply remove this additional path variable does the job. I used that in an earlier version of my code and I forgot that this is. My syntax also seems to be right.

  • Dynamic Actions disable button based on the text field

    Hello

    Sorry if this has already been asked but I checked and could not find a job.

    «I'm trying to disable / enable a button "view" among the elements of this region from if a text field has a value or.»  I created a dynamic action for this but its not working only partially.  I can get the button to be disabled or enabled when I leave the text field, but what I'm trying to do is to get the State of button to change as soon as I start to type in the text field or return to people with disabilities if the text is deleted.

    I don't know that I'm missing something simple and help you can give is greatly appreciated.

    I use APEX 4.1 and that's how I got the dynamic action implementation, I tried different but no event types to give them action I want.

    I also install an example (details below)

    Event - change

    Selection type - point

    Article (s) - P1_TEXT

    Condition - is null

    Real Action

    Action - disable

    Fires when the result of the event is - real

    Fire on the loading of the Page - Y

    Items affected - button

    Article (s) - P1_BUTTON

    Action of false

    Action - Enable

    Fires when the result of the event is - fake

    Fire on the loading of the Page - Y

    Items affected - button

    Article (s) - P1_BUTTON

    workspace - show_issue

    user_name - show_issue

    password - show_issue

    app_id - 61707

    http://Apex.Oracle.com/pls/Apex/f?p=61707:1

    It works as expected if you change the event of 'Change' for 'key version?

  • How to activate the FDF in page OAF (where DFF is based on the custom table).

    Hello Experts!
    I'm trying to to de facto in the page of the OFA. I'm not able to activate the FDF is used the custom table.

    Ex:
    Let's assume that my XX_DFF FDF uses this custom table XX_TABLE Att1, att2...
    I am able to activate the FDF in page OAF, but not able to do these values entered to get stored in the custom table.

    I need helping hands to tide me over for the FDF entered values stored in my custom table.

    Please provide me with the steps so that I can follow...

    Best wishes
    Thiru.

    Good.

    Pls close the message by mentioning what answer is useful or appropriate. This will ensure the reusability of the wire by other members of the forum.

    Reference http://forums.oracle.com/forums/ann.jspa?annID=914

    -Anand

  • Displacement of the custom fields of one vCenter to another

    Hello

    I need to move my vcenter (or all esx hosts) of my new vsphere vcenter. I connect just 3.5 esx host for my new vcenter.

    as for this nice guide iam able to move old vcenter custom fields to my vcenter vsphere using export-csv.

    http://www.virtu-al.NET/2009/05/29/PowerCLI-on-steroids-custom-attributes/

    -


    Snip-


    Snip
    Snip

    Snip
    -.

    1. The export of all the attributes that have been customized in a CSV (backup)

    $list = @)

    $vmArray.GetEnumerator () | %{

    $vmName = $_. Name

    $_. Value.Custom.getenumerator () | %{

    $row = New-Object psobject

    $row | Add-Member - memberType noteproperty-name VmName-value $vmName

    $row | Add-Member - memberType noteproperty-name NomAC-value $customKeyLookup [http://$_.Name|http://$_.Name]

    $row | Add-Member - memberType noteproperty-name CAValue-value of $_. Value

    $list = $row

    }

    }

    $liste | Export-Csv "C:\CA-backup.csv" - noTypeInformation

    -


    Snip-


    Snip
    Snip

    Snip

    Snip
    -.

    so I connect vi PowerCli to my old vcenter 'connect-viserver' and export all of the CF, "reconnect" all the esx 3.5 to my vsphere vcenter server, connect to my new vcenter and import them accordingly:

    -


    Snip-


    Snip
    Snip

    Snip

    Snip
    -.

    1. Import all custom from a CSV (restore) file attributes

    Import-Csv "C:\CA-backup.csv" | %{

    $vmArray [http://$_.VmName|http://$_.VmName]. Object.setCustomValue ($_.) NomAC, $_. CAValue( )

    }

    -


    Snip-


    Snip
    Snip

    Snip

    Snip
    -.

    I can't run this code as a script itself snippets and my PS skills are limited, so here's my Question: could someone help me to get started?

    I guess I need to plug my vCenter first... as "Connect-VIServer vcserver.

    your help is very appreciated. Thank you

    rgrds uxmax

    Hi, thanks for the link

    Yes, you will need to connect to your server of VI using the cmdlet connect-viserver, something like this should do:

    to connect-viserver MYVISERVER

    Or if you need to move from other credentails as the account that you are using this as a use:

    SE connect-viserver MYVISERVER-user "myuser" - pass "myP@ssword"

    Once you have done this, you can run the export and then use the same cmdlet to connect to the other server of VI before importing the details.

    I hope this helps.  As a no, I also activated on my blog comments, it's a good way for everyone to see, too, how solve us problems.

    If you found this information useful, please consider the allocation of points for correct or helpful.

    Alan Renouf

    http://Virtu-al.NET

  • Create the custom field on vm creation

    Hi all!

    Does anyone know if there is a way to create a custom field in each new virtual machine with the news of creation (Date/time and user)? I was thinking about a trigger in the vCenter but still lost in this...

    See Alan poster called runs a scheduled job PowerCLI

Maybe you are looking for

  • What software is better and safer to protect my Mac

    What software is better and safer to protect my Mac - OSX El Capitan 10.11.3? I was bombarded by MacKeeper advertising claiming recently that my Mac has "serious" problems and offering discounts of wholesale so that until recently the MacKeeper said

  • iPhone 5s does not save the steps of Apple Watch

    Just bought a brand new Apple Watch 42mm and paired with my iPhone 5 s. When I go to the activity app on my iPhone recordings of activity in the colorful journey circle and documents the calories. When I scroll through the steps it shows 0 steps. Mis

  • How can you see emails marketing Apple in English?

    Hello I'm writing this thread on this forum think I could ' t find a more appropriate. What I would like is simply to receive marketing emails (these advertising new iPhones and other Apple hardware) Apple in English only. When I click on a link at t

  • How to send data from the client to the server using tcp

    1. as I am new to watch I need help with sending data from client to server. I went through various examples of labview, but each of them also explains transfer of data to the client server. But I need help regardng send data from the server to the c

  • Windows does not recognize the Powershot A85 digital camera

    my camera is plugged in the Device Manager it is said that it works correctly, but it is not recognized by my windows 7 ultimate can someone help