Solved

Powershell to list all VM per datastore

Posted on 2010-11-21
5
3,296 Views
Last Modified: 2012-05-10
Hi All,

I got the following script to list all of the VM per datastore, but somehow it display blanks for certain VMs ?

Get-Datacenter | Get-VM | %{ $_.Name + " - " + (($_ | Get-Datastore | select Name).Name) | sort Name } | ft -AutoSize 

Open in new window


can anyone assist me here in refine this script ?

Thanks.
0
Comment
Question by:jjoz
  • 2
  • 2
5 Comments
 
LVL 22

Expert Comment

by:Luciano Patrão
ID: 34186917
Hi

What you man blank? I see no problem with that script.

Jail
0
 
LVL 1

Author Comment

by:jjoz
ID: 34186992
There's certain occasion in which the VM datastore went blank ?
eventhough the VM is actually running and working fine but it was reported as blank eg. no result ?
0
 
LVL 22

Expert Comment

by:Luciano Patrão
ID: 34187010
Hi

Check that VM and see if there is more than one Datastore allocated to that VM. If yes, then you need to create a Foreach to list all the Storage for each VM.

Jail
0
 
LVL 3

Accepted Solution

by:
Virtalicious earned 500 total points
ID: 34190713
Let me know if this gives you what you need...

Let me know!
-Virt

Comment: Lists the Datastores for each VM in a CSV file.


# NAME: VM-Datastore-Report.ps1
#
# COMMENT: Lists the datastores for each VM in a CSV file.  Output will be sent to
#                C:\scripts\output\VM-Datastore-report.csv.
# ==============================================================================================


Get-View -ViewType VirtualMachine | %{
      New-Object PSObject -Property @{
            Name = $_.Name
            Host = (Get-View $_.Summary.Runtime.Host).Name
            Datastore = [system.String]::Join(",",($_.Storage.PerDatastoreUsage | %{Get-View $_.Datastore} | %{$_.Name}))
      
      }
} | Export-Csv "C:\Scripts\Output\VM-Datastore-report.csv" -NoTypeInformation -UseCulture
0
 
LVL 1

Author Closing Comment

by:jjoz
ID: 34193646
Yes it works flawlessly !

thanks man.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
A brief introduction to what I consider to be the best editor for PowerShell.
Teach the user how to use create log bundles for vCenter Server or ESXi hosts Open vSphere Web Client: Generate vCenter Server and ESXi host log bundle:  Open vCenter Server Appliance Web Management interface and generate log bundle: Open vCenter Se…
Teach the user how to install log collectors and how to configure ESXi 5.5 for remote logging Open console session and mount vCenter Server installer: Install vSphere Core Dump Collector: Install vSphere Syslog Collector: Open vSphere Client: Config…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now