View Only
  • 1.  Get OS of VMs

    Posted Mar 26, 2021 04:01 AM


    I'm trying to get the Name and OS of all our VMs using VMware Tools, if VMtools isn't running or the query fails, then I'd like to get the OS from the VM properties. The reason for this, is because we have had cases where a VM has had it's OS upgraded but the VM OS property was not manually changed so the guest OS and the OS listed in the properties do not align.

    The script I've written below produces a lot of errors saying "Export-CSV: the process cannot access the file....etc"

    Any help to optimise this script and ensure that each result is appended to the CSV file would be appreciated.

    A side question, what's the best language to choose for PowerShell in the insert/edit code drop down for readability for future posts?






  • 2.  RE: Get OS of VMs
    Best Answer

    Posted Mar 26, 2021 06:53 AM

    When the script uses the 2nd Export-Csv, the is in use by the 1st Export-Csv.

    You could do something like this, which uses the pipeline to pass the data to Export-Csv.

    I use 'C#' for the code blocks, by lack of a better option. I just wish they had PS in the list.


  • 3.  RE: Get OS of VMs

    Posted Mar 26, 2021 01:04 PM

    Excellent this works perfectly, thanks! Thanks for the heads up about the code blocks too.

    Final question, a small set of the results either had a blank host name or a blank OS.Is there a way to put in some error catching to a log so I can see what ones failed and why, so I can resolve them?