1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
| $vserver="10.111.111.22"
$vuser="youname"
$vpwd="yourpasswd"
filter Convert-IP2Decimal
{
([IPAddress][String]([IPAddress]$_)).Address
}
filter Convert-Decimal2IP
{
([System.Net.IPAddress]$_).IPAddressToString
}
$IPPrefix="10.111.31"
$startIp=$args[0]
$startHostname=$args[1]
$num=$args[2]
$gateway="10.111.31.254"
$netmask="255.255.255.0"
$cpu=4
$mem=8
$template="template-centos7"
$vhost17=,"10.111.17.1","10.111.17.2","10.111.17.3","10.111.17.4"
$vhost20=,"10.111.20.1","10.111.20.2","10.111.20.3","10.111.20.4"
$vhost31=,"10.111.31.1","10.111.31.2","10.111.31.3","10.111.31.4"
function LoginVSphere($server,$user,$pwd){
Connect-VIServer -Server $server[0] -User $server[1] -Password $server[2] -EA "Stop"
}
LoginVSphere($vserver, $vuser, $vpwd)
$temp=Get-OSCustomizationSpec TestLinux
for($n=[int]$startIp;$n -le [int]$num; $n++)
{
$ipaddr=-Join($IPPrefix,'.',$n)
$hostname=-Join($startHostname,$n)
$temp|Get-OSCustomizationNicMapping|Set-OSCustomizationNicMapping -IpMode UseStaticIP -SubnetMask $netmask -DefaultGateway $gateway -IpAddress $ipaddr
new-VM -Name $hostname -Template $template -VMHost 10.111.31.5 -OSCustomizationspec TestLinux -Confirm:$false
Get-VM -Name $hostname|Set-VM -MemoryGB $mem -NumCPU $cpu -Confirm:$false
}
|