Solved

PowerCli

Posted on 2014-02-05
8
287 Views
Last Modified: 2014-02-24
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
Comment
Question by:sara2000
  • 5
  • 2
8 Comments
 
LVL 28

Expert Comment

by:asavener
ID: 39837089
Are you querying an individual host, or a vCenter (where you need to traverse each cluster and/or host)?
0
 

Author Comment

by:sara2000
ID: 39837161
vcentre,  and find the vm datastore.
0
 
LVL 28

Expert Comment

by:asavener
ID: 39837177
Ah.  You know the name of the VM, and you want to find what datastores it's using?
0
 

Author Comment

by:sara2000
ID: 39837199
I know the data store and want to find which VMs are in that datastore
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 28

Expert Comment

by:asavener
ID: 39837239
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
 
LVL 28

Expert Comment

by:asavener
ID: 39837240
Oh, whoops.

Just a sec....
0
 
LVL 28

Accepted Solution

by:
asavener earned 500 total points
ID: 39837243
(Get-Datastore -Name 'datastore_name').Extensiondata.Vm|%{(Get-View -Id $_.toString()).name} | Export-Csv <filename>
0
 
LVL 117
ID: 39837265
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When we have a dead host and we lose all connections to the ESXi, and we need to find a way to move all VMs from that dead ESXi host.
Last article we focus in how to VMware: How to create and use VMs TAGs – Part 1 so before follow this article and perform the next tasks, you should read the first article how to create the TAG before using them in Veeam Backup Jobs.
Teach the user how to configure vSphere clusters to support the VMware FT feature Open vSphere Web Client: Verify vSphere HA is enabled: Verify netowrking for vMotion and FT Logging is in place or create it: Turn On FT for a virtual machine: Verify …
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now