Solved

PowerCli

Posted on 2014-02-05
8
291 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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 118
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
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…
This video shows you how to use a vSphere client to connect to your ESX host as the root user. Demonstrates the basic connection of bypassing certification set up. Demonstrates how to access the traditional view to begin managing your virtual mac…

914 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

15 Experts available now in Live!

Get 1:1 Help Now