Solved

Powershell to list all VM per datastore

Posted on 2010-11-21
5
3,372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 23

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 23

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Teach the user how to convert virtaul disk file formats and how to rename virtual machine files on datastores. Open vSphere Web Client: Review VM disk settings: Migrate VM to new datastore with a thick provisioned (lazy zeroed) disk format: Rename a…
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…
Suggested Courses

617 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