cannot validate argument on parameter 'name' error in vmotion

Hi, all experts:

I am trying to use the powercli to vmotion some servers, the server names are defined in the file vms.txt, but it gave me some error. however, the vmotion still happens and the vms had been moved over to the new host. Please help me take a look.


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> gc .\vms.txt|%{Get-VM -Name $_ | Move-VM -Destination ca-vmhost09.xxxx.xxx -runasync}

Name                           State      % Complete Start Time   Finish Time
----                           -----      ---------- ----------   -----------
RelocateVM_Task                Running             0 04:12:54 PM
RelocateVM_Task                Running             0 04:12:56 PM
Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At line:1 char:29
+ gc .\vms.txt|%{Get-VM -Name $_ | Move-VM -Destination ca-vmhost09.xxxx.xxx-ru ...
+                             ~~
    + CategoryInfo          : InvalidData: (:) [Get-VM], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Jason YuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:
The problem lies in your vms.txt file.
gc .\vms.txt|%{ Write-Host "VM Name: $_" }

Open in new window

If you get any lines where it's just "VM Name: " you'll get exactly that error message.

One really simple way around that is this:
gc .\vms.txt| Where-Object { $_.Trim() } | %{Get-VM -Name $_ | Move-VM -Destination ca-vmhost09.xxxx.xxx -runasync}

Open in new window

That will drop blank lines or lines which are nothing but spaces.

Chris
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jason YuAuthor Commented:
got it, thank you, i will try it out.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.