Solved

Powershell to list all VM per datastore

Posted on 2010-11-21
5
3,261 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
Comment Utility
Hi

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

Jail
0
 
LVL 1

Author Comment

by:jjoz
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Yes it works flawlessly !

thanks man.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When we have a dead host and we lose all connections to the ESXi, and we need to find a way to move all VMs from that dead ESXi host.
Will try to explain how to use the VMware feature TAGs in the VMs and create Veeam Backup Jobs using TAGs. Since this article is too long, I will create second article for the Veeam tasks.
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 use vSphere Update Manager to update the VMware Tools and virtual machine hardware version Open vSphere Client: Review manual processes for updating VMware Tools and virtual hardware versions: Create a new baseline group in vSp…

763 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

6 Experts available now in Live!

Get 1:1 Help Now