PowerCLI collection – Adding hosts to inventory

With several projects at several sites I have come along a nice list of powerCLI oneliners or scripts. I wanted a place to have these scripts in a handy catalogue online, maybe share and learn on some blogging skills (or be a little louder than only 140 characters). I know there are probably already place online, but..how can I learn the bloggin. So here goes…

This example is a script that adds 24 hosts to a vCenter inventory. ESXi is installed, vCenter and PowerCLI are setup. PoweCLI has a connection setup to the vCenter (Connect-VIServer -Server <vc> -Protocol HTTPS). No other automation or scripting is in place.

To add 24 hosts to a inventory:

1..24 | Foreach-Object { Add-VMHost hostesxi$_.example.nl -Location (Get-Datacenter DataCenter) -User root -Password “<replace>” -RunAsync -force:$true}

So what does this one do:

  •  1..24; Amount of hosts. This is piped to the command and used by the $_ variabel. Foreach-Object let’s us loop within the 1..24 range so the hosts number will change every loop.
  • Add-VMHost is actually the PowerCli cmdlet to add the host.
  • hostesxi$_.example.nl. Creates hostnames of hostesxi1_.example.nl till hostesxi24.example.nl in the datacenter DateCenter
  • -User and Password are the user and password for access to the ESXi hosts.
  • -RunAsync option is to let the tasks run parallel.

Published by

Pascal

Who Am I? Well please to meet you ...I'm Pascal van de Bor and I work as an EUC Consultant/Architect for all kinds of customers. I have been working in IT for ages, doing some networking, Linuxes/Unixes, storage and a little scripting in PowerShellCLI / Perl / PHP along the way. Virtualization became my main area of expertise when I came in contact with VMware and later on a little Citrix and Hyper-V. I work, and worked, at different companies that need EUC expertise on a project/contract basis. I do this at my employer ITQ at the moment. Going from assessing and designing, consultancy, implementation and on the job training for the EUC team. Main focus is the VMware product suite, but I’m not afraid of a little outside of the box. It’s all about synergy isn’t it…. In 2014, 2015, 2016 and 2017 I am awarded vExpert. Great to be part of the community. Outside this blogging space, I love some gaming on the Xbox One, riding my motorcycle around (for the people that only see a flash, I currently ride a Yamaha FZ6-N S2) or playing one of my guitars (Gibson SG, Ibanez electric for shredding and Ibanez steel-string) and listening to (and visiting) music. A little preference for the loud music, but can also enjoy other genres. If you want to get in touch, ask here, follow my twitter feed. Please do connect! - See you around

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.