Hi All I can't figure out what I'm doing wrong. I can get Host profile to remediate with this way:
$hostdns = '192.168.1.24'
$profile = 'vmlabs-master-hp'
#step2
$VMHost = Get-VMHost $hostdns
$profilename = Get-VMHostProfile -Name $profile
#step3
Invoke-VMHostProfile -profile $profilename -entity $VMhost -AssociateOnly -confirm:$false
$AdditionalConfiguration = Invoke-VMHostProfile -profile $profilname -entity $VMHost -ApplyOnly -confirm:$false
$AdditionalConfiguration.GetEnumerator()| select Name
#step4
$AdditionalConfiguration[‘network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-DSwitch-MGMT-vmk0"].ipConfig.IpAddressPolicy.subnetmask'] = "255.255.255.0"
$AdditionalConfiguration[‘network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-DSwitch-VMOTION-vmk1"].ipConfig.IpAddressPolicy.address'] = "10.1.1.24"
$AdditionalConfiguration[‘network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-DSwitch-VMOTION-vmk1"].ipConfig.IpAddressPolicy.subnetmask'] = "255.255.255.0"
$AdditionalConfiguration[‘network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-DSwitch-VSAN-vmk2"].ipConfig.IpAddressPolicy.address'] = "10.2.2.24"
$AdditionalConfiguration[‘network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-DSwitch-VSAN-vmk2"].ipConfig.IpAddressPolicy.subnetmask'] = "255.255.255.0"
$AdditionalConfiguration[‘network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-DSwitch-NFS-vmk3"].ipConfig.IpAddressPolicy.subnetmask'] = "255.255.255.0"
$AdditionalConfiguration[‘network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-DSwitch-NFS-vmk3"].ipConfig.IpAddressPolicy.address'] = "100.10.10.24"
$AdditionalConfiguration[‘network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-DSwitch-MGMT-vmk0"].ipConfig.IpAddressPolicy.address'] = "192.168.1.24"
#step5 - View hash table
$AdditionalConfiguration | ft -AutoSize
#step6 - Remediate
Invoke-VMHostProfile -Entity $vmhost -Variable $AdditionalConfiguration -Confirm:$false
But can't get it working when trying to import info from csv and hash table like this: (With method it attaches the profile but doesn't apply anything)
$answerfile = Import-CSV C:\scripts\ProfileAnswers.csv
#Loop through each row and apply host profile
foreach($data in $answerfile) {
$profile = Get-VMHostProfile $data.profile
#Set VMhost variable to be able to pipe objects
$VMhost = Get-VMhost $data.hostname
Write-Host Starting ($VMhost.name)
#Attach host profile to host
Invoke-VMHostProfile -profile $profile -entity $VMhost -AssociateOnly -confirm:$false
#Get hash table for answer file and assign to configuration
Write-Host “Getting Hash Table Answer File”
$AdditionalConfiguration = Invoke-VMHostProfile -profile $profile -entity $VMHost -ApplyOnly -confirm:$false
#Switch Statement to read in hash table and then set keys for Vmotion IP and Management IP on DVS
$var = @{}
If($AdditionalConfiguration){
switch ($AdditionalConfiguration.GetEnumerator()){
{$_.name -like ‘*MGMT*.address’ }{$var += @{$_.Name = $data.mgmtip}
}
{$_.name -like ‘*MGMT*.subnetmask’}{$var += @{$_.Name = $data.mgmtmask}
}
{$_.name -like ‘*VMOTION*.address’}{$var += @{$_.Name = $data.vmotionip}
}
{$_.name -like ‘*VMOTION*.subnetmask’}{$var += @{$_.Name = $data.vmotionmask}
}
{$_.name -like ‘*VSAN*.address’}{$var += @{$_.Name = $data.vsanip}
}
{$_.name -like ‘*VSAN*.subnetmask’}{$var += @{$_.Name = $data.vsanmask}
}
{$_.name -like ‘*NFS*.address’}{$var += @{$_.Name = $data.nfsip}
}
{$_.name -like ‘*NFS*.subnetmask’}{$var += @{$_.Name = $data.nfsmask}
}
}
}
#Set Host in maintenance mode, apply profile with answer file, test for compliance
Write-Host “Apply Profile to $VMHost”
#Set-VMHost -VMHost $VMhost -State ‘Maintenance’
Invoke-VMHostProfile -Entity $vmhost -Variable $var -Confirm:$false #| Test-VMHostProfileCompliance
}
######## CSV ##########
"hostname","mgmtip","mgmtmask","vmotionip","vmotionmask","vsanip","vsanmask","nfsip","nfsmask","profile"
"192.168.1.24","192.168.1.24","255.255.255.0","10.1.1.24","255.255.255.0","10.2.2.24","255.255.255.0","100.10.10.24","255.255.255.0","vmlabs-master-hp"