Hello,
I have installed on a server VMWare ESXi 4.1.0. On this installation, I have two datastores (datastore1 and datastore2) and on each datastore I have a virtual machine; now, I found a simple script that help me to backup a virtual machine: in this script I retrieve the datastore with this line of code:
# We get the datastore of the machine
$ds = Get-Datastore -Server $vh -VM $vm
were $vh and $vm are the connection to the server and the (one) virtual machine on that server.
What I expect is the datatstore related to that $vm but instead the Get-Datastore retrieves both the datastores on the server: is this the behaviour of this function?
In what mode I can retrieve the datastore related to $vm ?
--
Regards,
Marco Mangiante
P
Hi Marco,
you should remove the -Server parameter. So it will be:
# We get the datastore of the machine
$ds = Get-Datastore -VM $vm
this will list the name of datastores associated to the VM.
Connect-VIServer <server>
$HardDisk = Get-VM -Name <VM name>| Get-HardDisk
$HardDisk.FileName.Split("]")[0].TrimStart("[")
Hello Robert,
Robert van den Nieuwendijk ha scritto:
Hi Marco,
you should remove the -Server parameter. So it will be:
# We get the datastore of the machine
$ds = Get-Datastore -VM $vm
I tried it but even this retrieves the 2 datastores. For simplicity, this is the code that I'm using:
# Connet to ESX
$vh = Connect-VIServer -Server $server -Port 443 -User $login -Password $password
# Get the machine we are interested in
$vm = Get-VM -Server $vh -Name $machine
#Get the datastore of the machine
$ds = Get-Datastore -VM $vm
where $server, $login, $password and $machine are parameters passed from command line.
--
Regards,
Marco Mangiante
Are you sure that all of the disks of the VM are on the same datastore? If you split the disks of the vm over multiple datastores then the Get-Datastore cmdlet will return all these datastores.
Hi Marco,
Maybe any iso connected to vm ?
Get-VM $vm | Get-CDDrive | FT Parent, IsoPath #and please, show output Get-HardDisk -VM $vm
Also check where is vmx file is located.
Have you any snapshots on VM ?
Hello Robert,
Robert van den Nieuwendijk ha scritto:
Are you sure that all of the disks of the VM are on the same datastore? If you split the disks of the vm over multiple datastores then the Get-Datastore cmdlet will return all these datastores.
I have 2 physical hdd: on datastore1 (first hard disk) there is the ESXi and the virtual machine that name I pass to the script at command line, on the second datastore (on the second hard disk), there is the virtual machine where I excute the script.
Maybe is this the problem?
--
Regards,
Marco Mangiante
then the output you are getting now is expected, both datastores will be listed. Because the VM is associated to both datastore1 and datastore2.
Hello,
yezdi ha scritto:
then the output you are getting now is expected, both datastores will be listed. Because the VM is associated to both datastore1 and datastore2.
so, to summarize:
datastore1 -> vm-test (that I pass to the script to backup)
datastore2 -> svr-bck (where I execute the script)
So, I execute the script on svr-bck to backup vm-test and so vm-test is associated to both datastores?
--
Regards,
Marco Mangiante
No, that doesn't make sense.
Can you do
Get-VM -Name vm-test | Get-HardDisk | Select Name,FileName
to see where the harddisk(s) are located.
And this
$vm = Get-VM -Name vm-test
$vm.ExtensionData.LayoutEx.File | Select Name
should let us see if there are any other (non-VMDK) files on the 2nd datastore.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
