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.
LVL 1
sara2000Asked:
Who is Participating?
 
asavenerConnect With a Mentor Commented:
(Get-Datastore -Name 'datastore_name').Extensiondata.Vm|%{(Get-View -Id $_.toString()).name} | Export-Csv <filename>
0
 
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
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

 
asavenerCommented:
Ah.  You know the name of the VM, and you want to find what datastores it's using?
0
 
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
 
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
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.

All Courses

From novice to tech pro — start learning today.