hi:
i have to many new esxi host need add to my Vcenter,when it done, i have to many things to do.Like edit the vswitch,add the VDS ...
so i writed a script to do thoes things for me.
The script works like this:
1.add the new host to vc;
2.set the vmhost to Maintenance mode;
3.attach a vmhost profile.
4.apply the vmhost profile.
5.exit the Maintenance mode.
the script can do 1 2 3 well,but it can't apply the profile.can anyone help me ,and explain why?
-----------------------------------------------------------------------------------------------the script---------------------------------------------------------------------------------------------------------------------
Write-Host "Your VC password:"
$VP = Read-Host
Write-Host "Your ESXI Password:"
$EP = Read-Host
Connect-VIServer 192.168.10.11 -Protocol https -User administrator@vsphere.local -Password $VP
$hostlist = Import-Csv d:\test1.csv
foreach ($host01 in $hostlist)
{
Add-VMHost -Name $host01.host -Location $host01.Cluster -User root -Password $EP -Force
Set-VMHost -VMHost $host01.host -State Maintenance
$HashTable = Get-VMHost -Name $host01.host |Apply-VMHostProfile -Profile Cluster-01 -Confirm:$false
$HashTable['network.hostPortGroup["key-vim-profile-host-HostPortgroupProfile-VMKernel_VMotion"].ipConfig.IpAddressPolicy.address'] = $host01.VMkernel_VMotion
$HashTable['network.hostPortGroup["key-vim-profile-host-HostPortgroupProfile-VMKernel_VMotion"].ipConfig.IpAddressPolicy.subnetmask'] = $host01.NETMASK
Get-VMHost -Name $host01.host | Apply-VMHostProfile -Variable $HashTable -Confirm:$false
$VSPG = Get-VMHost -Name $host01.host | Get-VirtualPortGroup
Set-VMHost -VMHost $host01.host -State connected
}
Write-Host "Done!"
----------------------------------------------------------------------------------------------end------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------the csv file-------------------------------------------------------------------------------------------------------------------
host | Cluster | VMkernel_VMotion | NETMASK |
192.168.10.24 | Cluster-01 | 192.168.21.24 | 255.255.255.0 |
| | | |