Placing o/p on multiple lines from read-host -prompt

Hi All,

New to the forum, and never knew it existed…
We receive requests to migrate multiple VMs between clusters and data-centers. I have the code setup to do the migrations with no issue, and manually put the VM names into a text file, and then update the code with the target cluster. I am trying to automate the process so other people do not have to touch the code.
I am doing the Read-Host -Prompt and putting the o/p into the text file to read. However, I cannot figure out how to put multiple lines in and then have the cluster next to the VM name as a target.
E.G… VM1234567 Cluster-12345
VM234455 Cluster-23456
The snippet of code I am using is:
Read-Host -Prompt ‘Type name of VM and cluster name that will be migrated’ | Out-File -FilePath C:\TEMP\vm_list.txt -Append
This gives me 1 VM and 1 target cluster name.
I have tried to loop but it is not working.
Any help would be appreciated.
Gary

gary,
Welcome to the forum. :wave:t4:

In my experience it is a bad idea to give the user the chance to enter free text. A better option would be to provide a list of choices the user can choose from. That reduces the chance for failures drastically.

And if you query more than one property you should query them separately and store them in a CSV file instead of plain text. This way you can access them individually when needed.

it is not working” is not helpful at all. :smirk: … what does that mean? Do you get errors? If yes please share them here completely (formatted as code)

and BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink: