Help with a one-liner

OK, just a bit of fun...

I want to get the path of the vmx and vmdk my VMs files in a spreadsheet, the following works somewhat, but it duplicates the vmxpath for each disc, I'm sure that this could also be done in a single line, but I can't quite reach, go Luke , you know you like a challenge!


Connect-VIServer MYVISERVER
$vms = Get-VM

$myCol = @()
foreach ($vm in $vms)
{
$MyDetails = "" | select-Object Name, VMXPath, Disks
$MyDetails.Name = $vm.Name
$MyDetails.VMXPath = ($vm | Get-View).Summary.Config.VMPathName
$MyDetails.Disks = $vm | Select -ExpandProperty HardDisks | Select Filename
$myCol += $MyDetails
}
$myCol | Select Name, VMXPath -ExpandProperty Disks


Alan Renouf

http://Virtu-al.NET

The following script is the solution, but I'm afraid that I can't ride in a single line

$list = @()
Get-View -ViewType VirtualMachine | % {
     $row = New-Object psobject
     $row | Add-Member -MemberType noteproperty -Name Name -Value $_.Name
     $row | Add-Member -MemberType noteproperty -Name VMXPath -Value $_.config.files.vmpathname
     $row | Add-Member -MemberType noteproperty -Name NrDisk -Value $_.Layout.Disk.Count
     for($i = 0; $i -lt $_.Layout.Disk.Count; $i++){
          $row | Add-Member -MemberType noteproperty -Name Disk$i -Value ($_.Layout.Disk[$i].DiskFile[0])
     }
     $list += $row
}
$list | Sort-Object -Property NrDisk -Descending | select * -ExcludeProperty NrDisk | Export-Csv "C:\temp.csv" -NoTypeInformation -UseCulture
Import-Csv "C:\temp.csv" -UseCulture | Sort-Object -Property Name | Export-Csv "C:\VMDK-report.csv" -NoTypeInformation -UseCulture

There are a few things to fix:

(1) the number of disks is not always the same, so it is impossible to pre-define the properties beforehand.

==> This can be solved by adding properties with the Add-Member cmdlet

(2) the Export-Csv cmdlet apparently resembles the first row of the table to determine the number of columns in the CSV file.

==> This has been resolved by adding a temporary NrDisk property that contains the number of VMDK has a specific guest. The table can then be sorted in descending order on this property. This way the guest who has the largest number of disks will be on the first row of the table.

(3) we do not want to see additional property NrDisk in the CSV file

==> This has been resolved by using the parameter - Excludeproperty on the Select-Object cmdlet.

(4) the CSV file must of course be sorted on name of the guest.

==> This has been resolved by the first CSV of writing to a temporary file, read the CSV file (where now each row of the table has all the properties), sort the array and the array of writing the ultimate CSV

Message to Alan: next time you're bored try the times crossword

Tags: VMware

Similar Questions

  • Need help with an order line shaped PowerCLI to follow development snapshots

    Hello

    I use Vshpere 5.1 and I need help to use PowerCLI out of information to audit some VM backups.

    My ultimate goal is to be able to verify which machines are being backed up.  Our backup tool uses instant VMware to run incremental backups so if we can follow what made instant due VM / deleted then we can better verify backups.

    I decided my inexperience with PowerCLI that it would be preferable for me to try a few small orders to see if I could get some decent results.

    The line of code I'm starting with is Get - VM * | Get-VIEvent - MaxSamples 20 | Where-Object {$_.} FullFormattedMessage - eq "task: Remove Instant"} ".

    Most of the time this script works however the output is interesting for me.

    Info: VMware.Vim.TaskInfo

    Key: 5360442

    ChainId: 5360442

    Createduserid: 2014/06/20 22:32:31

    Username: JJarvis

    Data Center: VMware.Vim.DatacenterEventArgument

    ComputeResource: VMware.Vim.ComputeResourceEventArgument

    Host: VMware.Vim.HostEventArgument

    VM: VMware.Vim.VmEventArgument

    Ds                   :

    Net                  :

    Dvs                  :

    FullFormattedMessage: Task: Remove Instant

    ChangeTag:

    DynamicType:

    DynamicProperty:

    Frankly, I was glad I was able to sign anything, but I'm confused as to why under "VM: 'told'"Vm: VMware.Vim.VmEventArgument"instead of the actual name of the VM."

    If I can find it to output the actual name of the Virtual Machine, so I can start to play with the formatting and obtained Export CSV files.  Any help you can offer would be much appreciated.

    Thank you

    I suspect a calculated property might be the way to go.

    Something like that

    Get - VM * | Get-VIEvent - MaxSamples 20 | Where-Object {$_.} {FullFormattedMessage - eq ' task: Remove Instant "} |

    Select @{N = 'The virtual computer name'; E={$_. Vm.Name}}

    You can of course view other properties of events returned to the Select-Object cmdlet even.

  • Help with xbox one

    Is anyway I can project my screen of mobile phone (samsung galaxy s4) to the TV using my 'Xbox ONE' on its last updated?

    Hello

    Your Question is beyond the scope of this community...

    I suggest that repost you in the Xbox Forums.

    "Xbox a Preview program FAQ.

    http://support.Xbox.com/en-us/Xbox-one/system/Xbox-update-preview-FAQ

    'Home'

    http://forums.Xbox.com/

    "Xbox forums.

    http://forums.Xbox.com/xbox_forums/general_discussion/f/3817.aspx

    _________________________________________________

    "Xbox Forums directory.

    http://www.Xbox.com/en-us/forums

    General

    Material & Discussion Services

    Xbox support
    Agent hours: M - F 09:00-17:00 PT

    Law enforcement forums

    Technical support of Xbox Live rewards
    Xbox Live rewards Squad hours: M - F 09:00-17: 00 PST

    See you soon.

  • Install the second HARD drive in my Inspiron 1720... : () Please help with this one

    Hello

    you just bought a faster (7200 RPM) 60 gb 2.5 "SATA (of course) for my Inspiron1720 - idea is to keep the system on it.

    Anyway, opened the Bay where are hard disks, and I noticed there is some sort of connector for my current hard drive (the thing has a kind of bent pins to plug the drive hard vertivally)

    because I don't want to replace it, to add another, I am devoid of this connector, faq explains only how to replace not add a second.

    Summer:

    http://dellcommunity.com/supportforums/board/message?board.ID=cc_faq&message.ID=350

    that read, however it means only (part number) type PATA and SATA got :(

    Now, I spent all day in the city, searching ebay and allegro (sort of Polish to ebay ;])

    Couldn't find it anywhere, so how can I connect the new drive?

    I couldn't find info about it on the net, so it's not a common problem, so how people add new hard drives to their 1720s?

    So what now? is it possible to get this connector? what I buy from Dell? : smileymad: (that would really bother me) or should I have got one when I bought my inspiron? (don't have the box at the moment, is in my second home, so can not verify)

    Will be much gratefull for info, as it starts to irritate me, can I just plug into my new hard drive in a DELL computer.

    See you soon

    Tomek


  • 1 important update is never installed. Code 8007007E update: KB 94895 need help with this one. I would be very grateful!

    I can't find similar situations

    Check this KB number, please.

    Previous discussions about the error: http://www.google.com/search?hl=en&safe=off&rls=com.microsoft: en - US & q = + site: social.answers.microsoft.com + social.answers.microsoft.com + 8007007e & ei = SpXIAcPElAfKz9mHCw-bud & his = X & oi = nshc & resnum = 1 & ct = more results, & ved = 0CAsQ2AQ ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • Hello. Can anyone help with this one?

    As I go to export my calendar, I get a message saying""offline Media is present and will be encoded using the chart to offline media. I can't find any material offline in the project... and it takes more than 3 hours for the output media. Thanks in advance!

    In your project window go to view metadata > Premiere Pro project metadata and check that "offline properties" is checked. Hold your option/alt key to expand all the folders in your project. Navigate across to the column and you should find the culprit in offline mode.

  • Help with one-liner & Get - VM vmnic

    Hello

    I need help with this single line. I want to get everything as vnmic for vmnic0 & line type. Everything underneath works but how to retrieve vmnic0 type also?

    Get - vm | Select Name, Powerstate, NumCpu MemoryMB, @{N = "OSFullname"; E={$_. Guest.OsFullName}}

    Thank you

    If you do

    Get - VM TEST01 | Get-NIC

    has an entry called "NIC 1?

  • A pen as a tool with a diagonal line through it appeared that I cannot get rid where work around. He is NOT one of the tools on the standard toolbar. Help please

    A pen as a tool with a diagonal line through it appeared that I cannot get rid where work around. He is NOT one of the tools on the standard toolbar. Help please

    Means generally that you're trying to work on a layer locked.

  • Help with the line chart

    I created a line chart in Illustrator CS3.  Everything is great, except that I need to change the colors of the lines.  There are two lines total.  I can't select just one line to change the color.  When I use the white arrow selection tool he will choose only a point-by-point and not the whole line.

    If I use the black arrow selection tool then selects all of the chart.

    Thanks a lot for any help on this!

    It's fine even if you have a selected point you can change the color of the line, make sure you change the color of the outline, not the color of the file.

    If you want to be treated and have all selected Bézier points (or select all lines in a group), hold the option key and click with the hollow tool to select all Bézier points. Option click again to select multiple levels within the group. The result will be the same whether in the postscript file produced Illustrator.

  • Need help with the attempt to copy of 1 line of text

    Hi all

    I hope someone can point me in the right direction. I use DW for many years and write php/mysql code with it. This weekend, I downloaded and instalt a copy of CS4 new. I am trying to learn all the ins and outs new.

    I use Dreamweaver and am writing a php script. I'm in Code view and I have my page structured with all php at the top of the page code between my <? PHP and? > symbols and all my html form code at the bottom. I am trying to copy a single line of php code in my script to paste in the same script is a bit further in the code.

    I hightlight the line of code using the left button of the mouse and press Ctrl-C. When I do this, DW highlights all the php code of the symbol open until the symbol of closure and the screen display then moves to the top of the page. This same behavior occurs if I pointed out and do a right click to select copy on the shortcut menu.

    I'm just trying to copy one line of code, so it's really very strange to me!

    Should I have an incorrect parameter value?

    Someone else knows it?

    And help at all?

    Thank you

    Dennis

    This has been discussed to death. Simply click on the top item in the area more Like This on the right.

    It is an intermittent problem. I've never met to work on several machines and operating systems. Others find themselves constantly tormented. The key to find out what causes it is to find the common element which triggers the problem. Nobody has managed to do so far.

    It seems that have a change in the page before trying to copy eliminates the problem. Others have also found that the workspace switch clears the problem.

  • BlackBerry 8800 Smartphone, symbol of the battery with a red line through it. Does not start. Help, please!

    I recently bought a 8800 and when I inserted a battery, I got was a battery symbol with a red line through it, on a dark screen.  I changed the batteries, tried to charge it via the USB port and a wall outlet without result.  I tried cleaning the contacts and tried to download t a new OS, but it does not recognize the phone when it is in reality.    I am at the end of my rope with this phone and can't figure out what else to do.  It is just gone? Please help me

    Clipboard?

    You will need to use JL_Cmder to wipe the device and then load the operating system on the device. Follow the instructions here:

    http://www.BlackBerryFAQ.com/index.php/How_do_I_wipe_the_BlackBerry_using_Jl_Cmder%3F

    If JL_Cmder does not work, follow this instruction:
    http://www.BlackBerryFAQ.com/index.php/What_to_do_next_if_Jl_Cmder_will_not_connect_and_wipe

    It might not work. You should try a connection with JLCmder 20 to 25 times, as well with the battery and the battery.

    See what's happening.

  • Help with the query to select only one record from the result set in double

    Hello

    Please help with the query. Version of Oracle database we use is 10g R2.

    I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec

    ID
    Org
    DF
    Sec Sub-Sec

    (163)CQCPDMCPDMHD(163)PCENGENGENG(163)CQASICASICIS8888TSTACTACTAC(163)TSHEHESW6789CQINFOINFOFOS6789PCSECSYSSECSYSINFO16789TSSECSYSSECSYSINFO29009PCBMSBMSBMS1

    My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.

    ID
    DSB

    DF
    SEC
    Sub-Sec
    (163)CQCPDMCPDMHD8888TSTACTACTAC6789CQINFOINFOFOS9009PCBMSBMSBMS1


    Thank you

    Orton

    Hello

    This sounds like a job for ROW_NUMBER:

    WITH got_r_num AS

    (

    SELECT id, DSB, df, s, sub_sec org

    ROW_NUMBER () OVER (PARTITION BY ID.

    ORDER BY org

    ) AS r_num

    OF view_x

    )

    SELECT id, DSB, df, sub_sec s,

    OF got_r_num

    WHERE r_num = 1

    ;

    He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data.  (I know that you said that you were a view selection.  Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.  (I didn't quite understand the explanation above.  I don't know why you want to

    ID ORG DF DRY SUB_SEC

    --      ---     --      ---     -------

    1234 CQ DPRK DPRK HD

    and is not

    1234 IS CQ ASIC, ASIC

    or

    TS 1234 IT IT SW

    or

    1234 CQ ASIC ASIC HD

    )
    If you change the query at all, post your modified version.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Need help with installation on Photosmart C7280 all-in-one

    I had my printer is installed and has been using the printer for 3 wireless laptops in my house.  Now, I can't even find my backup drive, so I have need help with downloading the software to use my printer and also get to use wireless.   I don't know what happened, but the fax for this printer is listed, but not the printer itself.   Help, please!

    Click here to download the software for your printer:

    http://h10025.www1.HP.com/ewfrf/wc/softwareCategory?product=3204785 & LC = on & CC = US & DLC = in & lang = to & CC = US

    has chosen the appropriate operating system that corresponds to your computer and download the full software features.

  • Help with e-all-in-one printer Officejet Pro 8610

    I just bought a HP Officejet Pro 8610 e-all-in-one printer.

    To my surprise, the paper tray can't handle legal-size paper - only format letter!  Do I need to buy a special paper for legal size tray?  Where?

    Although the printer has a USB port in the back (the so-called port USB Standard-B), it came not with a USB cable.  Is this normal?  I remember on previous purchases of HP printers they came with an extension cable USB with on one side a record Standard-A and Standard-B one at the other end.  Should I complain with HP?  To whom?

    Hello

    1 no, you don't need a different sandbox, plesae take off all the papers and you can see a diagram of how to measure the status bar,

    2. No, many printers now do not come with USB cables. I believe that HP provides that USB cables for printers sold in the AP region (Asia Pacific).

    Kind regards.

  • Help! Trying to amount of money with the duplicate lines

    I have a database that have the code bars the columns following, quantity, etc.. The barcode colum has duplicates of bar code and the corresponding quantity is different. I worked hours trying to solve how to summarize each different bar codes and replace the table with 1 bar code each corresponding total quantity. For example, instead of:

    971386447563
    971386447562
    971386447561
    971386605655
    971386605654
    971386617771
    971386622241
    971386704031
    971386792391
    971387149781
    971387162621
    971387396676
    971387396677
    971387396678

    I would like that it follows:

    971386447566
    971386605659
    971386617771
    971386622241
    971386704031
    971386792391
    971387149781
    971387162621
    9713873966721

    I used the following code, which selects only duplicates.

    < cfquery name = "CountBarcodesCart1" datasource = "inventory" >

    SELECT *.

    OF cart1

    WHERE barcode (IN)

    SELECT bar code

    OF cart1

    GROUP BY barcode

    SEEN (COUNTING (barcode) > 1))

    < / cfquery >

    Thanks for anyone who can help with my business.

    I know there are much better to do this, but I'll share the following code and hope it helps someone else. What I did change table CART1 to a TEMP table, get the added dupliates and then copy the corrected (with no duplicates) to a new data table. Then I delete the TEMP table.



    SELECT the barcode, Sum (Quantity) as the quantitysum
    TEMP
    GROUP BY barcode



           
    INSERT INTO Cart1 (bar code, quantity)
    VALUES (#CountBarcodesTemp.barcode #, #CountBarcodesTemp.quantitysum #)
     

    #barcode #-#QuantitySum #.



    DELETE *.
    TEMP

Maybe you are looking for