VMware Cloud Community
cchicken
Contributor
Contributor

powercli script to return array of virtual machines from text file input

Hi first time post / ask something here.  I am new to powercli and would appreciate some asstiance with the above.  To To clarify I would like to;

Read a list of virtual machine names from a .txt file OR possibly a .csv (as i attempted below) file into an Arrary.

I made an attempt with the following that failed Smiley Sad

$vms = @()

for (i$ in (import-csv vmlist.csv)) {$vms += get-vm -name i$}

Example Text File.

virtualMachine1

virtualMachine2

virtualMachine3

Reply
0 Kudos
4 Replies
aravinds3107
Virtuoso
Virtuoso

Welcome to the Communities..

Check if this post helps http://communities.vmware.com/thread/315193

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful |Blog: http://aravindsivaraman.com/ | Twitter : ss_aravind
Reply
0 Kudos
cchicken
Contributor
Contributor

Thank you, but that is not quite what I am after.  To clarify I am not attempting to create VMs.  The VMs in my text file exist in my VC environment.  The text file is a dump of computer obects from a AD group.  I just need to create an array of thoes machines from the text file.  Once I have an array, something like $vms = get-VM * I can iterate over the arrary to update some custome attributes.  Thanks

Reply
0 Kudos
cchicken
Contributor
Contributor

Ok, took a good look at import.csv and made the following changes to resolution.

Thew out .txt file and went with .csv

Added Colume Heading "Name" and below this added the following VM names

virtualmachine1

virtualmachine2

virtualmachine3

for (i$ in (import-csv vmlist.csv)) {$vms = get-vm -name $i.Name}

Rather simple

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

Discusion moved from VMware vCenter™ to VMware vSphere™ PowerCLI.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos