small script output formatting

Hello Experts,

I'm trying to start with powerCLI, am very new to scripting.

want to go is to recover 'VMName OSFullName, IPAddress, host, data store' for a specific virtual machine or the VM...

To do this, I wrote

Param ($VMName)

$vm = get - VM $VMName

$vmg = get-VMGuest $vm

$vmg | HostName, IPAddress, OSFullName FT

Very well so far.

Then I don't understand how get Host IE ESX Server where the virtual computer and the data store that is used by this specific virtual machine.

If we see $vm | FL we see "docking" as one of the goods... I want that it should be displayed in my exit...

$vmg | FT, OSFullName, IPAddress, $vm host name. Host? something like that? It did not work

Even for the data store, if we see $vm | Get-data store, we get the name of the data store.

Please help me with this, I don't need to an advanced script, a simple solution that can fit into what I'm trying to do here...

You are tryingh mix properties of 2 variables in the cmdlet Select-Object/Format-Table 1.

It does not work like that.

But you can do

$vm = Get-VM $VMName
$vmg = Get-VMGuest $vm

$vmg | FT HostName, OSFullName, IPAddress, @{N="Host";E={$vm.Host.Name}},@{N="Datastore";E={($vm | Get-Datastore).Name}}

____________

Blog: LucD notes

Twitter: lucd22

Tags: VMware

Similar Questions

  • Strange script output format

    I have a problem I can not quite understand. I execute a command that returns a string like this:
    Server name: VM_TEST1
    All I get is the value after the VM_, which corresponds to the actual name of the server. VM_ designated as a virtual machine. So I try to get just TEST1. I can do the following


    $name_temp = $name | Select-String - pattern "servername" | Out-string. foreach {$_.split(":") [-1]}

    I'm left with: VM_VMTEST1 so I remove spaces before and the VM_

    $name = $name_temp. Remove (0.4)

    Now I find myself with just the name, but for some reason when I run the script is output like this:

    TEST1

    TEST2

    TEST3


    I do not understand why he puts three lines between each server name.  This happens if I run the CLI, powergui or even export to a file.

    The problem you have is the combination of the Select-String and out-string cmdlets. The Select-String cmdlet does not return a string but returns a Microsoft.PowerShell.Commands.MatchInfo object. For example:

    IgnoreCase: true

    LineNumber: 1

    Line: Server name: VM_TEST1

    File name: InputStream

    Path: InputStream

    Model: Name of the server

    Context:

    Matches: {server name}

    If you use the out-string cmdlet to a string of this object, it adds blank lines.

    As you can see the original line is the line of this object property. We can use this line property in our code. Like this:

    $name_temp = $name | Select-String - Pattern "servername" | ForEach-Object {$_.} {Line.Split ('_') [1]}

    Best regards, Robert

  • Question output formatting

    Hello community! Sorry, it's so rudimentary. Can anyone offer advice on how to better format the output of the below? As it is, it prints it just without formatting - I want out as the output format-table and I would have zero decimal places in the output of Write-Host $CurrentItemHdd.CapacityGB.  Thank you!

    foreach ($VmItem to $MyVms)

    {

    $CurrentItemHdd = get-disk hard - VM $VmItem

    Write-Host $VmItem.Name $CurrentItemHdd.CapacityGB

    }

    To create an exit in your PowerCLI script like the Format-Table output, you must create an output object. There are several ways you can do. One way is to use the PowerShell New-Object as shown in the below script cmdlet. The properties in the New-Object cmdlet output are not classified. That's why I redirect the output to the Select-Object cmdlet to order.

    Your original script will generate a table for the CapacityGB property, if a virtual machine has more than one hard drive. That's why I introduced a second foreach to browse the hard drives. Because you probably want to know that CapacityGB belongs to the hard drive, I added the property 'hard drive '.

    [Math] .NET: Round() function is used to supplement the CapacityGB to zero decimal places.

    The character '&' at the beginning of the script and the scriptblock around the script are necessary to allow to channel the output of the script to another cmdlet as Export-CSV. foreach is not a cmdlet, and therefor you cannot use the out of foreach in the pipeline without using this trick.

    & {foreach ($VmItem to $MyVms)

    {

    foreach ($CurrentItemHdd in (Get-disk hard - VM $VmItem))

    {

    New-Object PSObject-property @ {} TypeName

    VM = $VmItem.Name

    "Hard drive" = $CurrentItemHdd.Name

    CapacityGB = [Math]: Round($CurrentItemHdd.CapacityGB,0)

    } |

    Select-Object - property, CapacityGB VM, 'Hard drive'

    }

    }}

    Post edited by: Robert van den Nieuwendijk

  • Simultaneous report runs very slowly when the output format is 'XML' on IBM 6.1

    We have recently updated one of our test server database IBM AIX 5.3 to 6.1 operating system. We are witnessing a strange question in the execution time-out of simultaneous reports that have output in XML format (no server of publication and the Publisher). Whenever the output format is set to XML, the execution time seem to have increased very high than it used to be less than 5.3. A report to take 10 seconds which takes about 4 minutes to complete which is huge in comparison. Information about the version as below

    Oracle EBS 11.5.10

    Oracle 10.2.0.4.0 DB

    IBM AIX 6.1 OPERATING SYSTEM

    Oracle reports 6.0.8.28.0 (I know old enough)

    Provide expert advice.

    Thank you!

    All the

    We have solved the problem. I would like to share for the benefit of the readers of the community, if they are facing similar problems.

    The reason for the slowness of the report was due to lack of installation of the 'VIEW' option that is used when XML reports. Reports whose outputs are in format PDF, XML, HTML etc, Post Script, they all need a virtual display makes setup and configuration properties of config pointing to this server whenever settings are do. It could be a windows machine with X-Server running on it for display purposes or it could be services that are running on the same server for Unix/Linux applications where the application runs. We have installed VNC as X-Server that hosts services for virual (X) output for display on UNIX itself and have configured it in the reports configuration file. It seems to have solved the problem and the reports are run as expected (must faster!)

    Thank you

    Girish

  • ud32 output format

    Hi all

    We use ud32 to test service using fml32 buffer. One of the result field is a double, when the value of the field data are displayed in exponential format.

    Is it possible config output format? I don't want no exponential format. Its config possible in ud32?, it's a shell config?

    I thank in advance.

    Hello

    Unfortunately, there is not a way to control the release of ud/ud32. It just uses Fprint() which uses the format string "%g" to print floats and doubles. What you're asking for sounds reasonable. As an alternative it would be not difficult to use a script (awk or other) to convert the exponential value to format numbers in no exponential format.

    If you really need, I would suggest opening and enhancement with the Oracle customer support request.

    Kind regards
    Todd little
    Chief Architect of Oracle Tuxedo

    PS ud/ud32 is really a pretty simple utility and it reproduce yourself would not be a lot of work.

  • Change default value of output format you 'Keynote 09 '.

    Hi all

    I use Keynote 6.6.2 and I need your help to know how to use the 'Keynote ' 09"as the default output format, without an export each time.

    In my company, I'm the only one with this version of Keynote, if no one else can use my files and allows us to work on the same files really often!

    Thank you for helping me.

    Kind regards

    Nicolas

    The only way to create 09 files from Keynote 6.6.2 is to use file > export > Keynote 09

  • Met an output Format of D3D (unknown) on Windows Vista 32-bit, what this could be?

    Output format unknown D3D on Windows Vista, while trying to activate the game simulator of mining & Tunnelling?

    Need help!
    Jack

    Hello

    D3D error could be because the DirectX wrong on the computer.

    Download and install the latest version of DirectX from here:

    Use DirectX Runtimes (June 2010): http://www.microsoft.com/en-us/download/details.aspx?id=35

    If DirectX update does not help because the error is activation, you can contact Tunneling and mining simulator manufacturer for more assistance.

  • SELECT statement in the script output window

    Hello

    SQL Dev 4.0.3

    is it possible to include select statements from the command run the Script in the Script Output window?

    Is the result in the window:

    Select 1... ;

    results

    Select 2... ;

    results

    Joop

    try to put "set echo on" (without the quotes) as the first line and make sure that you use F5 to run the script... like sqlplus.

  • SQL output format

    Dear all,

    Select emp_no in emp;

    my output is

    1

    2

    3

    4

    But I want that as output format

    1,2,3,4

    Could you please tell me which application should I write it to achieve.

    Concerning

    Rajat

    Hi, Rajat,

    This is called the aggregation of the chain and this page:

    ORACLE-BASE - String aggregation Techniques

    shows several ways to do so.  What sense does use?  It depends on your requitrements and your version of Oracle.  The LISTAGG built-in aggregate function is good for most purposes.

  • Hi I download twice id70543955 vector, but its very small image and format have I can't use this image so I want to come back two right.thanks

    Hi I download twice id70543955 vector, but its very small image and format have I can't use this image so I want to come back two right.thanks

    Hello

    I apologize for the inconvenience.

    I added 2 images of credit in your account.

    Hope that helps!

    Kind regards

    Sheena

  • Output formatting in a sql

    Hello

    I have 4 columns, I need the output format using carriage returns between values and removing the label for nulls, such as only the columns filled with values are displayed:

    Name: emp.first_name

    Medium: emp.middle_name

    Name: emp.last_name

    Address (line 1): emp.ext_contact_addr1

    for example: -.

    If the name is null then output would be

    Middle: Thomas

    Family name: James

    Address (line 1): 10 william st

    If the name is null, then output would be

    First name: Tessa

    Family name: James

    Address (line 1): 10 william st

    etc...

    Please help me.

    Hello

    Here's a way

    SELECT LTRIM (NVL2 (emp.first_name

    , ' Name: '. EMP.first_name

    NULL

    )

    || NVL2 (emp.middle_name

    , CHR (10) | ' Average: ' | EMP.middle_name

    NULL

    )

    || NVL2 (emp.last_name

    , CHR (10) | ' Last name: ' | '. EMP.last_name

    NULL

    )

    || NVL2 (emp.ext_contact_addr1

    , CHR (10) | ' Address (line 1): ' | EMP.ext_contact_addr1

    NULL

    )

    , CHR (10)

    ) AS output_string

    WCP

    ;

    Using NVL2 like this, the label for each line gets concatenated only if there is some data to go with it.

    If the name is NULL, which means that the output_string will begin with a character of new line (which is CHR (10) on my system, you may need to change this).   I used LTRIM to remove this first newline character, if there be one.

    You can also consider the results of unpivoting so that you have between 0 and 4 lines in the result set for each row in the emp, with 4 items on separate lines.

  • Get and Set of dynamic Type via the Script output

    I am running vRO 6.0.1. I built a dynamic type to Veeam. I can see the items in the inventory and can select them as attributes in workflows. I'm looking to get the dynamic Type via a script object and set it as a variable in the script output, but its does not work. I created the dynamic type using the type dynamic plug-in generator v2.

    I have 'Veeam' namespace with types:

    VeeamHost

    jobFolder

    job

    I put an output with the 'DynamicTypes:Veeam.job' type attribute and the name jobOut

    My script is just:

    jobOut = Server.findForType ('DynamicTypes:Veeam.job' '29714267-f517-4f76-a621-902b3e789772/urn:veeam:Job:26eddcda-ea52-469b-b4c9-0b80fec098ae');

    System.log ("Job found:" + jobOut "'); 

    After the execution of the jobOut variable is empty. In the newspapers, I see:

    Found job: DynamicWrapper (Instance): [DynamicTypesDynamicObject]-[class com.vmware.o11n.plugin.dynamictypes.model.DynamicObject] - VALUE: dynobj: [__ns:Veeam __id:29714267-f517-4f76-a621-902b3e789772/urn:veeam:Job:26eddcda-ea52-469b-b4c9-0b80fec098ae __tp:DynamicTypes:Veeam.job]

    Does anyone have an idea of how complete the release of DynamicTypes:Veeam.job with the actual work of veeam I got via the script?

    Could check you what happens if you replace the line

    jobOut = Server.findForType("DynamicTypes:Veeam.job","29714267-f517-4f76-a621-902b3e789772/urn:veeam:Job:26eddcda-ea52-469b-b4c9-0b80fec098ae");

    with

    jobOut is DynamicTypesManager.getObject ("Veeam", "task", "29714267-f517-4f76-a621-902b3e789772/urn:veeam:Job:26eddcda-ea52-469b-b4c9-0b80fec098ae");.

  • Help: Output Format complex

    Hello

    Data in TAB_DTL for an APPID using, I need to generate a report in the following format.
    CREATE TABLE TAB_DTL
    (
    APPDATE          DATE,
    AMOUNT          NUMBER(12,2),
    STATUS          VARCHAR2(1),
    RATE          NUMBER(5,2)
    );
    
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '13/09/2011 10:50:45 AM','DD/MM/YYYY HH:MI:SS AM'), 500000, 'D', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '09/11/2011 1:15:30 PM','DD/MM/YYYY HH:MI:SS AM'), 5000, 'R', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '15/12/2011 3:20:31 PM','DD/MM/YYYY HH:MI:SS AM'), 5000, 'R', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '05/01/2012 10:25:11 AM','DD/MM/YYYY HH:MI:SS AM'), 5000, 'R', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '02/02/2012 4:23:34 PM','DD/MM/YYYY HH:MI:SS AM'), 5000, 'R', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '05/03/2012 11:15:45 AM','DD/MM/YYYY HH:MI:SS AM'), 5000, 'R', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '30/03/2012 11:55:10 AM','DD/MM/YYYY HH:MI:SS AM'), 5000, 'R', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '31/03/2012 11:59:00 AM','DD/MM/YYYY HH:MI:SS AM'), 470000, 'B', 13 );
    
    
    OUTPUT FORMAT :
    
    APPDATE                    DR          CR     BALANCE          ACCAMT     DAYS     CUMM      
    13/09/2011 10:50:45 AM          5,00,000.00     0     5,00,000.00     10301     58     10301
    09/11/2011 1:15:30 PM          0          5000     4,95,000.00     6330     36     16631
    15/12/2011 3:20:31 PM          0          5000     4,90,000.00     3655     21     20286
    05/01/2012 10:25:11 AM           0          5000     4,85,000.00     4823     28     25109
    02/02/2012 4:23:34 PM          0          5000     4,80,000.00     5456     32     30565
    05/03/2012 11:15:45 AM          0          5000     4,75,000.00     4218     25     34783
    30/03/2012 11:55:10 AM          0          5000     4,70,000.00     334     2     35117
    31/03/2012 11:59:00 AM          0          0     4,70,000.00     35117
    For the calculation of A logic) DAYS: difference in days of the next later Date
    (B) ACCAMT: Balance * (unlike in the days of the next Date) * rate / days in the year

    With the help of CASE / SQLs of LEAD, the same thing can be accomplished.

    Thank you
  • Error in the REST Web Service with the text output Format

    Hi all

    I am referencing a REST web service and can successfully connect to it and retrieve the results with the output XML value Format.

    I don't need the node values, I want to just grab the entire XML string and fill a table with her column.

    When I create a new Rest web service reference, including the text output Format value and then create a form/report to run it, I get the following error when I click on "send":

    ORA-06550: line 1, column 63: PLS-00103: encountered the symbol "end-of-file" when expects it one of the following numbers: (- + new case mod not null to other current County avg exists max min prior sql stddev sum variance execute forall time timestamp interval date fusion pipe)
    Error sending request.

    There is control in the XML characters, but surely, this is handled by the Apex, so I'm not sure what the problem is here.

    Any ideas most welcome.

    Thank you
    Rhodri

    Rhodri:

    Request Express waiting for answer text actually be answer text, delimited by other characters that denotes a new value and a new Recordset. You should leave the response as XML. The XML document will be stored in the column xmltype01 in the collection that you specify. You can then convert this column xmltype01 in a clob, if you like using the. toClobVal().

    Kind regards

    Jason

  • The Get-VMResourceConfiguration script output

    Hey guys im trying to a csv file with the output of each part of vms and and the number of shares they have. I'm a big Powershell basics, I am learning well so I thought to ask gurus here. I'll place a copy of the script here.

    If I run the command Get-VMResourceConfiguration - VM xxx | Format-List-property CpuSharesLevel for example, I get the result OK but when I try the same thing in my script it doesn't work.

    $start = get-Date

    # Make an array with the result I want.
    # Name, then the property I want in the output.
    # A lot of sandfordit.com of the wiki code it thx much borrowed.

    $table = New-Object system. Data.DataTable 'results '.

    $col1 = New-Object system. Data.DataColumn ([string]) name
    $col2 = New-Object system. Data.DataColumn NumCpuShares, ([string])
    $col3 = New-Object system. Data.DataColumn CpuSharesLevel, ([string])

    $table.columns.add ($col1)
    $table.columns.add ($col2)
    $table.columns.add ($col3)

    $duration = (new-TimeSpan (Get-Date) $start). TotalSeconds
    "Lagde tahon etter $duration sekunder.

    # Me make a list of vmms in a folder of the virtual Center

    $vms = get-file Boris_test | Get - VM | Sort - the property name

    $duration = (new-TimeSpan (Get-Date) $start). TotalSeconds
    "Inte antall vmer etter $duration sekunder.

    foreach ($vm to $vms)
    {
    $row = $table. NewRow()

    $row. Name = (Get-VM-name $vm). Name
    $row. NumCpuShares = (Get-VMResourceConfiguration - VM $vm |) Property Format-List-NumCpuShares). NumCpuShares
    $row. CpuSharesLevel = (Get-VMResourceConfiguration - VM $vm |) Property Format-List-CpuSharesLevel). CpuSharesLevel

    $table. Rows.Add ($row)
    "Til rad for $vm.
    }

    $duration = (new-TimeSpan (Get-Date) $start). TotalSeconds
    "Tahon fyllt ut etter $duration dry.

    $table | Format-Table
    $table | Export-Csv-path test.csv

    THX Boris

    Hi Boris,.

    If you change the two lines:

    $row. NumCpuShares = (Get-VMResourceConfiguration - VM $vm |) Property Format-List-NumCpuShares). NumCpuShares
    $row. CpuSharesLevel = (Get-VMResourceConfiguration - VM $vm |) Property Format-List-CpuSharesLevel). CpuSharesLevel

    in:

    $VMResourceConfiguration = get-VMResourceConfiguration - VM $vm

    $row. NumCpuShares = $VMResourceConfiguration.NumCpuShares
    $row. CpuSharesLevel = $VMResourceConfiguration.CpuSharesLevel

    your script works.

    In the new code, I inserted an additional line to call Get-VMResourceConfiguration only one time. This will make the script a bit faster.

    Best regards, Robert

Maybe you are looking for

  • Factory reset was completed?

    I borrowed a phone originally, I used my icloud for connection and other things, but when I gave him back I factory reset it so all my information did not exist on however, I just receive a text asking the PIN code I had used for the phone while I go

  • ITunes Store does not not on Iphone s Plus 6

    I have a 6 s. Until last night, the app store ITunes worked fine. The ITunes store has now stopped working. When I click on the app, it's a blank white screen. No idea how can I fix? Thank you

  • Initialization of controls on the front

    Hello On my front, I have several controls that the user must set before executing the program. The user mostly enters values that each time that on the front before running the program.  Is it possible to save these values in the control on the fron

  • to access the QML attached objects in C++ and best practices for the handling of the user interface in classes

    Hello I have in fact 2 queries (1) how can we access attachedobjects defined in QML in C++? (2) I'm loving development on Blackberry 10 C++ is one of my favorites. But I'm a bit lost when it comes to managing the user interface in classes. For exampl

  • USB ports not working no-Windows 7 on Imac

    Hello I ve just installed Windows 7 on an Imac end 2012, using an external hard drive and running in Bootcamp. Everything went well, Win 7 works perfectly, but all USB ports do not work. Everything I plug into their t doesn't get recognized (flash me