foreach
($data in $answerfile)
{
#Set VMhost variable to be able to pipe objects
$VMhost = Get-VMhost $data.hostname
Write-Host "Starting $VMhost.name"
#Attach host profile to host
Apply-VMHostProfile -profile $data.profile -entity $VMhost -AssociateOnly -confirm:$false | Out-Null
#Get hash table for ansfer file and assign to configuraiton
Write-Host "Getting Hash Table Answer File"
$AdditionalConfiguration = Apply-VMHostProfile -profile $data.profile -entity $VMHost -ApplyOnly -confirm:$false
#example below for variable names to create new hash table based on wildcards. Will remove in future iteration
#$AdditionalConfiguration['network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-SVD-VSM03-dell-management-management"].ipConfig.IpAddressPolicy.address'] = $data.mgmtip
#$AdditionalConfiguration['network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-SVD-VSM03-dell-management-management"].ipConfig.IpAddressPolicy.subnetmask'] = $data.mgmtsubnet
#$AdditionalConfiguration['network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-SVD-VSM03-dell-vmotion-vmotion"].ipConfig.IpAddressPolicy.address'] = $data.vmoip
#$AdditionalConfiguration['network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-SVD-VSM03-dell-vmotion-vmotion"].ipConfig.IpAddressPolicy.subnetmask'] = $data.vmosubnet
#Switch Statement to read in hash table and then set keys for Vmotion IP and Management IP on DVS
$var = @{}
switch ($AdditionalConfiguration.GetEnumerator())
{
{
$_.name -like '*management*.address' } {
$var += @{$_.Name = $data.mgmtip}
}
{
$_.name -like '*management*.subnetmask'} {
$var += @{$_.Name = $data.mgmtsubnet}
}
{
$_.name -like '*vmotion*.address'} {
$var += @{$_.Name = $data.vmoip}
}
{
$_.name -like '*vmotion*.subnetmask'} {
$var += @{$_.Name = $data.vmosubnet}
}
#Default {
#$value = Read-Host "Please provide a value for ${$_.Name}"
# $var +=@{$_.Name = $value}
# }
}
#Set Host in maintenance mode, apply profile with answer file, exit maint, test for compliance
Write-Host "Apply Profile to $VMHost"
Set-VMHost -VMHost $VMhost -State 'Maintenance' | Apply-VMHostProfile -Variable $var -Confirm:$false | Set-VMHost -State 'Connected' | Test-VMHostProfileCompliance
}