Zade
Enthusiast
Enthusiast

Report for checking what VMS are on what datastores in environment

Jump to solution

Is there a way of running a daily report on which VMS are on which datastores?

0 Kudos
1 Solution

Accepted Solutions
markdjones82
Expert
Expert

Here is the modified, i didn't test it

connect-viserver vcenter

get-datastore | % {

$datastore = $_

$_ | Get-VM | Select Name,@{N="Datastore"; E={$datastore.Name}} } | Export-csv -notypeinformation "E:\location\VM_Report.csv"

disconnect-viserver vcenter

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com

View solution in original post

0 Kudos
19 Replies
markdjones82
Expert
Expert

I would suggest using a powercli scrip which you could setup as a scheduled task

$datastore =Get-Datastore

$datastore | % { $_ | Get-VM | Select Name,@{N="Datastore"; E={$datastore.Name}} } | Export-csv -notypeinformation VM_Report.csv

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
Zade
Enthusiast
Enthusiast

Hi Mark,

Thanks for the information, would I be running this via PowerCLI? or within powershell itself?

Is there a way I can set a location of the VM_Report.csv file? Say if I wanted to run to E:\VM_REports\VM_report.csv

0 Kudos
IBMSupport
Contributor
Contributor

Hello

RVTools extract is the best option, In which you have the option to export the report in .CSV format as well.

- Vinutha

markdjones82
Expert
Expert

Zade,

  You would run this via Powercli not just powershell.  You would also need to connect to your virtual center first:  connect-viserver virtualcenter .   Yes, you can set the path to however you like and name the report however you like I just put that name as an example.  The account running the script will need permissions to virtualcetner if you are not familiar with powercli.

Here is a link on how to create a powercli scheduled task: http://www.virtu-al.net/2009/07/10/running-a-powercli-scheduled-task/

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
0 Kudos
Zade
Enthusiast
Enthusiast

Hi Mark,

Can you give me an example of the script with a location on? So I can save it out locally ?

I'm not sure on which part of the script you add the location you want to save the file?

0 Kudos
markdjones82
Expert
Expert

It was like how you had it Smiley Happy

connect-viserver vcenter

$datastore =Get-Datastore

$datastore | % { $_ | Get-VM | Select Name,@{N="Datastore"; E={$datastore.Name}} } | Export-csv -notypeinformation "E:\location\VM_Report.csv"

disconnect-viserver vcenter

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
0 Kudos
Zade
Enthusiast
Enthusiast

Great thank you Mark, I've managed to get this to run, now I just need to figure out how to schedule it

0 Kudos
markdjones82
Expert
Expert

There are ways to convert to HTML and stuff, but that is a little more advanced.

I would highly suggest learning Powercli if you are a day to day VM admin it is a highly valuable tool for mass reports and changes.  There is a really good Powercli forum here as well where people can help out

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
0 Kudos
Zade
Enthusiast
Enthusiast

Thanks Mark,

I've created a .ps1 file and added everything in, it seems to run but on the last part when disconnecting, it comes up and says "are you sure you want to disconnect" Y or N, is there a way of it just disconnecting automatically?

I take it once its working I can just set this up to run via windows scheduled task

0 Kudos
markdjones82
Expert
Expert

Yeah i forgot that part it is -Confirm:$TRUE

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
0 Kudos
Zade
Enthusiast
Enthusiast

Hi mark,

I've added disconnect-viserver MYVCENTERSERVER -Confirm:$TRUE

but I still get the Y / N prompt, any ideas?

0 Kudos
markdjones82
Expert
Expert

Sorry, my head is cloudy today  should be -confirm:$FALSE

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
0 Kudos
Zade
Enthusiast
Enthusiast

hi mark, so something like this?

disconnect-viserver vcentername -confirm:$FALSE

0 Kudos
Zade
Enthusiast
Enthusiast

Hi Mark,

It appears to be showing all of my datastores next to the VM name, rather than one or two specific datastores that the vm resides on, any ideas?

0 Kudos
markdjones82
Expert
Expert

Here is the modified, i didn't test it

connect-viserver vcenter

get-datastore | % {

$datastore = $_

$_ | Get-VM | Select Name,@{N="Datastore"; E={$datastore.Name}} } | Export-csv -notypeinformation "E:\location\VM_Report.csv"

disconnect-viserver vcenter

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com

View solution in original post

0 Kudos
Zade
Enthusiast
Enthusiast

Worked really well thank you !

0 Kudos
Zade
Enthusiast
Enthusiast

Hi Mark,

Is there a way of adding this to save the .csv file onto another server?

If so what can I add to do this?

I have this at the moment from what you gave me:

connect-viserver VCENTER

get-datastore | % {

$datastore = $_

$_ | Get-VM | Select Name,@{N="Datastore"; E={$datastore.Name}} } | Export-csv -notypeinformation "E:\VMReports\VM_Report.csv"

disconnect-viserver VCENTER -confirm:$FALSE

0 Kudos
markdjones82
Expert
Expert

You should be able to write to any UNC path or share.  So just substitute that into the path.

Export-csv -notypeinformation "\\servername\sharename\vm_report.csv"

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
0 Kudos
Zade
Enthusiast
Enthusiast

Yep, got it! worked well thanks very much

0 Kudos