Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell to list all VM per datastore

Posted on 2010-11-21
5
Medium Priority
?
3,506 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 24

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 24

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 2000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Teach the user how to configure vSphere Replication and how to protect and recover VMs Open vSphere Web Client: Verify vsphere Replication is enabled: Enable vSphere Replication for a virtual machine: Verify replicated VM is created: Recover replica…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

916 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