Hi,
here what I want:
I want a list of all VMs, which are running on datastores, which names start with 02.
I tried with get-datastore where name 02* | get-vm , but this didn't work.
Regards
angoletti1
Get-VM -Datastore (Get-Datastore -Name 02*) |select-object -property Name |format-table -hidetableheaders > FileName.txt
Try something like
Get-VM -Datastore (Get-Datastore -Name 02*)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi angoletti1
Please refer the below script for the same
$server = get-viserver -server #To connect to server
$datastore = Get-Datastore -Name "02*" #To get the Datastore starts with 02
Get-VM -Datastore $datastore # Get all the VM's in the datastores starts with 02
I hope it resolves your issue. Please let me know if you have any issues in running the script.
Thanks
-Niket
hey, very good, that helps
Now one additional small thing: I want only see the name of the vm and write all this to a file.
Get-VM -Datastore (Get-Datastore -Name 02*) |select-object -property Name > FileName.txt
Hi
To view only the name just
$server = get-viserver -server 192.168.111.13 -user root -password esxadmin
$datastore = Get-Datastore -Name "02*"
Get-VM -Datastore $datastore | ft name # add ft name it will only display the names
To export in a file use the below code snippet
Get-VM -Datastore $datastore | Export-Csv -Path "C:\Data.csv" # it will display all the information about the VM's
I hope it resolves your issue
Thanks
-Niket
perfect, I'm very close to what I want.
The only thing is, that in the txt I see "Name", but I only want the server names with nothing else.
Get-VM -Datastore (Get-Datastore -Name 02*) |select-object -property Name |format-table -hidetableheaders > FileName.txt