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

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

PowerCli

I am looking for a script/comand to get VM and its datastore info.
I would appreciate if you can put me the comand to get this infomation in an excel or csv file.
0
sara2000
Asked:
sara2000
  • 5
  • 2
1 Solution
 
asavenerCommented:
Are you querying an individual host, or a vCenter (where you need to traverse each cluster and/or host)?
0
 
sara2000Author Commented:
vcentre,  and find the vm datastore.
0
 
asavenerCommented:
Ah.  You know the name of the VM, and you want to find what datastores it's using?
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
sara2000Author Commented:
I know the data store and want to find which VMs are in that datastore
0
 
asavenerCommented:
Usage:
FindVMDatastore.ps1 -vm <vm_name> -outfile <outputfile>

script text (save as FindVMDatastore.ps1):

$report = @()

connect-viserver <your_server_name>
$disks = Get-HardDisk -VM $vm | Select-Object name, filename
foreach ($disk in $disks) {
     $row = "" | Select VM, DiskName, FileName
     $row.VM = $vm
     $row.DiskName = $disk.name
     $row.FileName = $disk.filename
     $report += $row
}

$report | Export-Csv $OutFile -noTypeInformation
0
 
asavenerCommented:
Oh, whoops.

Just a sec....
0
 
asavenerCommented:
(Get-Datastore -Name 'datastore_name').Extensiondata.Vm|%{(Get-View -Id $_.toString()).name} | Export-Csv <filename>
0
 
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
Why not use the following:-

I would recommend using the following, also VMware recommends the use of PowerCLI, which is PowerShell interface with vSphere-specific additions.

http://communities.vmware.com/community/vmtn/server/vsphere/automationtools/powercli

One of the simplest PowerCLI examples, and something which is actually extremely useful on its own, is the Get-VM cmdlet. Which lists VMs.

PowerCLI can be a bit overwhelming to use,  But it can be enhanced with a nice toolset and a library of preconfigured scripts to jump-start your mass changes, which is possible with PowerGUI

http://powergui.org/index.jspa

and

VMware Community Pack

http://www.virtu-al.net/featured-scripts/vmware-powerpack/
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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