If any one having any other scripts please share
From here you will want to import your CSV and set to a variable:
#Import spreadsheet with hostname,mgmtip,mgmtsubnet,vmoip,vmosubnet for 1000v DVS input
$answerfile = Import-CSV ProfileAnswers.csv
You now have your answer file array set. We will loop through each item and repeat the code in the previous post to apply the host profile:
#Loop through each row and apply host profile
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 answer file and assign to configuration
Write-Host “Getting Hash Table Answer File”
$AdditionalConfiguration = Apply-VMHostProfile -profile $data.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 ‘*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, test for compliance
Write-Host “Apply Profile to $VMHost”
Set-VMHost -VMHost $VMhost -State ‘Maintenance’ | Apply-VMHostProfile -Variable $var -Confirm:$false |Test-VMHostProfileCompliance
}