Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3567
  • Last Modified:

Powershell to list all VM per datastore

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
jjoz
Asked:
jjoz
  • 2
  • 2
1 Solution
 
Luciano PatrãoICT Senior Infraestructure  Engineer  Commented:
Hi

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

Jail
0
 
jjozAuthor Commented:
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
 
Luciano PatrãoICT Senior Infraestructure  Engineer  Commented:
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
 
VirtaliciousCommented:
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
 
jjozAuthor Commented:
Yes it works flawlessly !

thanks man.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Building an Effective Phishing Protection Program

Join Director of Product Management Todd OBoyle on April 26th as he covers the key elements of a phishing protection program. Whether you’re an old hat at phishing education or considering starting a program -- we'll discuss critical components that should be in any program.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now