VMware Cloud Community
humbeljohn
Contributor
Contributor

Funciton vmotion error

Dear friend, 

I made a script to vmotion all VM on 172.30.12.64 host to 172.30.12.66, 

When I run the script, the red error displayed.

Where can I change it ,thanks

Code:

function vmotion ($vm)

{

  Move-VM $vm -Destination 172.30.12.66

  }

 

 

get-vmhost -name 172.30.12.64 |get-vm | Select-Object Name  -first 1 | out-file c:\vm.txt

$b=Get-Content "c:\vm.txt"

$j=$b.count

for ($i=3; $i -lt $j;$i++)

{

       vmotion $b[$i]

}

Error:

Move-VM : 5/11/2018 2:10:42 PM    Move-VM        Could not find VirtualMachine

with name 'TSTCCSER02.ARC

           '.

At D:\bt\vmotion2.ps1:3 char:3

+   Move-VM $vm -Destination 172.30.12.66

+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (TSTCCSER02.ARC ...

     :String) [Move-VM], VimException

    + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_ObjectNo

   tFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

You seem to be making it awfully complex.
Can you try this way, and check if you still have the issue?

Get-VMHost -Name 172.30.12.64 | Get-VM |

Move-VM -Destination (Get-VMHost -Name 172.30.12.66) -Confirm:$false


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
humbeljohn
Contributor
Contributor

Thanks, I knew the command worked before.

But what I want to do is vmotion all vm automatically to another host by running the script.

Automatically gets all vm info and export to a txt file, then run move-vm according to the txt file.

Reply
0 Kudos
LucD
Leadership
Leadership

Then try like this

$vms = Get-VMHost -Name 172.30.12.64 | Get-VM

$vms.Name | Out-File -FilePath c:\vm.txt

$vms | Move-VM -Destination (Get-VMHost -Name 172.30.12.66) -Confirm:$false


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
humbeljohn
Contributor
Contributor

thanks a lot , I also tried your code, it works,

I found the problem of my code,  vm name form vm.txt has space , so could not get object error.

I added trim(), it works. but still has the error.

Move-VM : 5/11/2018 6:12:22 PM    Move-VM        Value cannot be found for the

mandatory parameter VM

At D:\bt\vmotion2.ps1:4 char:3

+   Move-VM $vm -Destination 172.30.12.64

+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Move-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio

   n.ViCore.Cmdlets.Commands.MoveVM

function vmotion ($vm)

{

  Move-VM $vm -Destination 172.30.12.64

 

  }

 

 

get-vmhost -name 172.30.12.56 |get-vm | Select-Object Name -first 4| out-file c:\vm.txt

$b=Get-Content "c:\vm.txt"

$j=$b.count

for ($i=3; $i -lt $j;$i++)

{

     

        vmotion $b[$i].Trim()

}

Reply
0 Kudos
LucD
Leadership
Leadership

I'm not sure I understand why you insist on using this convoluted way of calling the vMotion, but I guess you have a good reason.

Anyways, are you sure the content of the $vm variable actually contains the name of a VM.
From the error message it looks as if the variable is empty.

Perhaps a blank line in the file?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos