Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PowerCli

Posted on 2014-02-05
8
Medium Priority
?
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 

Author Comment

by:sara2000
ID: 39837199
I know the data store and want to find which VMs are in that datastore
0
 
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 2000 total points
ID: 39837243
(Get-Datastore -Name 'datastore_name').Extensiondata.Vm|%{(Get-View -Id $_.toString()).name} | Export-Csv <filename>
0
 
LVL 123
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Ransomware is a malware that is again in the list of security  concerns. Not only for companies, but also for Government security and  even at personal use. IT departments should be aware and have the right  knowledge to how to fight it.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Advanced tutorial on how to run the esxtop command to capture a batch file in csv format in order to export the file and use it for performance analysis. He demonstrates how to download the file using a vSphere web client (or vSphere client) and exp…
This Micro Tutorial walks you through using a remote console to access a server and install ESXi 5.1. This example is showing remote access and installation using a Dell server. The hypervisor is the very first component of your virtual infrastructu…

670 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