VMware Cloud Community
Zade
Enthusiast
Enthusiast
Jump to solution

Report for checking what VMS are on what datastores in environment

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

Reply
0 Kudos
1 Solution

Accepted Solutions
markdjones82
Expert
Expert
Jump to solution

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

Reply
0 Kudos
19 Replies
markdjones82
Expert
Expert
Jump to solution

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
Jump to solution

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

Reply
0 Kudos
IBMSupport
Contributor
Contributor
Jump to solution

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
Jump to solution

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
Reply
0 Kudos
Zade
Enthusiast
Enthusiast
Jump to solution

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?

Reply
0 Kudos
markdjones82
Expert
Expert
Jump to solution

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
Reply
0 Kudos
Zade
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
markdjones82
Expert
Expert
Jump to solution

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
Reply
0 Kudos
Zade
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
markdjones82
Expert
Expert
Jump to solution

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

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
Reply
0 Kudos
Zade
Enthusiast
Enthusiast
Jump to solution

Hi mark,

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

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

Reply
0 Kudos
markdjones82
Expert
Expert
Jump to solution

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

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
Reply
0 Kudos
Zade
Enthusiast
Enthusiast
Jump to solution

hi mark, so something like this?

disconnect-viserver vcentername -confirm:$FALSE

Reply
0 Kudos
Zade
Enthusiast
Enthusiast
Jump to solution

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?

Reply
0 Kudos
markdjones82
Expert
Expert
Jump to solution

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
Reply
0 Kudos
Zade
Enthusiast
Enthusiast
Jump to solution

Worked really well thank you !

Reply
0 Kudos
Zade
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
markdjones82
Expert
Expert
Jump to solution

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
Reply
0 Kudos
Zade
Enthusiast
Enthusiast
Jump to solution

Yep, got it! worked well thanks very much

Reply
0 Kudos