Is there a way of running a daily report on which VMS are on which datastores?
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
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
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
Hello
RVTools extract is the best option, In which you have the option to export the report in .CSV format as well.
- Vinutha
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/
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?
It was like how you had it
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
Great thank you Mark, I've managed to get this to run, now I just need to figure out how to schedule it
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
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
Yeah i forgot that part it is -Confirm:$TRUE
Hi mark,
I've added disconnect-viserver MYVCENTERSERVER -Confirm:$TRUE
but I still get the Y / N prompt, any ideas?
Sorry, my head is cloudy today should be -confirm:$FALSE
hi mark, so something like this?
disconnect-viserver vcentername -confirm:$FALSE
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?
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
Worked really well thank you !
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
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"
Yep, got it! worked well thanks very much