content top

Batch Adding New VMware Hosts via PowerCLI

In building out a new VM Datacenter I had the task of adding quite a few VM hosts in short order. To make light work of adding multiple new hosts I decided to script it out and below are the results. It makes it easy:


####################################
#Add New VMware Hosts from TXT file#
#  Specifcy Parameters Below       #
#  http://vm-pro.com               #
####################################
$hostfile = get-content "C:\Scripts\new-hosts.txt"
$Location = "VMDatacenterOrClusterName"
$Username = "root"
$Password = ""
################################
$count = 0
foreach ($hostToAdd in $hostfile)
{
Write-Host $hostToAdd "Added to VMware DataCenter " $Location

Add-VMHost -Name $hostname  -Location $Location -User $Username -Password $Password -Force
$count = $count + 1
}
Write-Host "Total Hosts Added: " $count

As you can see, I’ve opted to specify all variables, including the location of a txt file containing each of my new vm hosts to add in, at the top of the script. This makes it much easier to customize and reuse in the future.
Ensure that your txt file contains only 1 host per line, and no additional markup.

We then loop through the text document adding hosts individually and displaying a little output to the console window via this command:

[powercli]
#
Write-Host $hostToAdd “Added to VMware DataCenter ” $Location
#
[/powercli]

Read More

PowerCLI – Essential Network Details

It often happens in the life of an engineer or systems administrator. Someone hands you a list of machines….may be physical, virtual or a mix of both. And they want to know “X” about these machines. Or maybe, you have a list of servers that are going to being P2Vd and you want to verify the networking information of the servers before and after. Here’s a quick script I spun up that will pull the active IP address, Gateway, Mask and both primary/secondary DNS entries.


$servers =  Get-Content c:\Scripts\ListOfServers.txt

Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $servers `
| where {$_.IPEnabled -eq 'True'} `
| Select dnshostname,{$_.ipaddress},{$_.defaultIPgateway},{$_.dnsserversearchorder[0]},{$_.dnsserversearchorder[1]},description `
| Export-Csv C:\Scripts\output\ListOfServers.csv

So what exactly is going on up there?

  1. Create and populate “C:\Scripts\ListOfServers.txt” with a list of Windows servers, 1 per line.
  2. We’re using WMI so we can pull information from both physical and virtual machines
  3. Where IP Traffic has been enabled (IPEnabled)
  4. Select ‘these’ columns (Server Name, IP Address, Gateway, and 1st and 2nd DNS entries, and the adapter description.

I found this great to have before doing some P2Vs as just a check to ensure each server had the correct basic IP information with only 1 script.

You’ll need a specific set of servers for this query, but it can be easily modified to search with a Get-VM cmdlet to retrieve a list of VMs (or even physical servers).

Read More

PowerCLI – Syntax Highlighter Brush

So as you’ve seen here and other wonderful web sites that feature any type of code, we put our code into ‘code blocks’ using Synatx Highlighter made famous by Alex Gorbachev.

# Here is an example of how you can put code into WordPress
# blogs using Syntax Highlighter Evolved with my PowerCLI Syntax Highlighter Brush

Get-VMHost | Get-VM | Get-VMGuest | select name,numcpu,memorymb

Name         NumCpu  MemoryMB
----         ------  --------
WindowsPDC1       1      1024
LinuxServer1      1      1024
WindowsPDC2       1      2048
LinuxServer3      1      4096

Given that he’s already developed a wonderful PowerShell brush, I added all the cmdlets provided by VMware PowerCLI version 4.0 Update 1.

Download Now:
PowerCLI Syantax Highlighter Brush
PowerCLI & Powershell Syntax Highlighter Evolved Brush
- Powershell 4.0 Update 1

Here is the link for Syntax Highlighter Evolved, which i’m using in this blog:
http://wordpress.org/extend/plugins/syntaxhighlighter/

Get many more excellent brushes in multiple languages from Abel here:
http://www.undermyhat.org/blog/2009/09/list-of-brushes-syntaxhighligher/

Read More

Hello! The First Post

Hello,

As our first post we’d like to keep things simple, say hello, and hopefully provide a little value though our a simple PowerCLI command

Basic Get-VM Powershell Command

The Get-VM command for a few select fields generates a simple table of your Virtual Machines on the host (if you’re connected to an ESX host) or you’re entire environment if connected to Virtual Center.

#Get-VM – Select certain properties and format as table

[vSphere PowerCLI] C:\> get-vm | select name,numcpu,memorymb
Name NumCpu MemoryMB
—- —— ——–
WindowsPDC1 1 1024
LinuxServer1 1 1024
WindowsPDC2 1 2048
LinuxServer3 1 4096

Read More
content top