How to read from a text file in PowerCLI console

I am moving bunch of vms from one host to another one. Is it a way I can make a text file and type all vmnames into this file, then run the following command with the file?


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VM -Name CCAAPP | Move-VM -Destination victoria.lacare.org -runasync

Name                           State      % Complete Start Time   Finish Time
----                           -----      ---------- ----------   -----------
                               Success           100 02:46:27 PM  02:46:27 PM


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VM -Name CCAKlgb | Move-VM -Destination victoria.lacare.org -runasync

Name                           State      % Complete Start Time   Finish Time
----                           -----      ---------- ----------   -----------
RelocateVM_Task                Running             0 02:47:37 PM


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VM -Name ccamgmt | Move-VM -Destination victoria.lacare.org -runasync

Name                           State      % Complete Start Time   Finish Time
----                           -----      ---------- ----------   -----------
RelocateVM_Task                Running             0 02:47:50 PM


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VM -Name ccaweb | Move-VM -Destination victoria.lacare.org -runasync

Name                           State      % Complete Start Time   Finish Time
----                           -----      ---------- ----------   -----------
RelocateVM_Task                Running             0 02:48:05 PM


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VM -Name ccawfs | Move-VM -Destination victoria.lacare.org -runasync

Name                           State      % Complete Start Time   Finish Time
----                           -----      ---------- ----------   -----------
RelocateVM_Task                Running             0 02:48:15 PM


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VM -Name ihmfapp | Move-VM -Destination victoria.lacare.org -runasync

Name                           State      % Complete Start Time   Finish Time
----                           -----      ---------- ----------   -----------
RelocateVM_Task                Running             0 02:48:30 PM


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VM -Name ihmfdb | Move-VM -Destination victoria.lacare.org -runasync

Name                           State      % Complete Start Time   Finish Time
----                           -----      ---------- ----------   -----------
RelocateVM_Task                Running             0 02:48:41 PM


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>
Jason YuAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

MazdajaiCommented:
Try

PS > gc .\vms.txt
CCAAPP
CCAKlgb
ccamgmt

gc .\vms.txt|%{Get-VM -Name $_ | Move-VM -Destination victoria.lacare.org -runasync}

Open in new window

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
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
VMware

From novice to tech pro — start learning today.