VMware Cloud Community
rxjoseph
Enthusiast
Enthusiast
Jump to solution

ESXi Host Customization and Answer file

Hi Experts 

Help me please 

https://nutzandbolts.wordpress.com/

I am using the script from the above blog to input IP address information to ESXi host on a cluster

When I run the script I get the following error

This the error message I get 

####################################################################################

Starting esxi701.contoso.com.name
Getting Hash Table Answer File
Method invocation failed because [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl] does not contain a method named 'GetEnumerator'.
At line:14 char:4
+ If($AdditionalConfiguration){
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

##########################################################################################

Input CSV file

HostnameMgmtIPMgmtSubnetVmoIPVmoSubnetProfile
esxi701.contoso.com192.168.130.128255.255.255.0192.168.130.152255.255.255.0Test1-Profile1

 

########################################################################################
$answerfile = Import-CSV $csv

#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 ‘*hostName*.name’ } {
$var += @{$_.Name = $data.hostName}
}
{$_.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
}

 

##########################################################################################

 

Please advise 

RXJ

 

Reply
0 Kudos
1 Solution

Accepted Solutions
rxjoseph
Enthusiast
Enthusiast
Jump to solution

Hi LucD

Correct it doesn't return any values

 

PS C:\Windows\system32> #Attach host profile to host
Apply-VMHostProfile -profile $data.profile -entity $VMhost -AssociateOnly -confirm:$false

Apply-VMHostProfile -profile $data.profile -entity $VMHost -ApplyOnly -confirm:$false


Name ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz MemoryUsageGB MemoryTotalGB Version
---- --------------- ---------- ------ ----------- ----------- ------------- ------------- -------
esxi701.contoso.com Maintenance PoweredOn 2 78 4992 1.153 3.995 6.7.0
esxi701.contoso.com Maintenance PoweredOn 2 78 4992 1.153 3.995 6.7.0

Many thanks

RXJ

View solution in original post

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

It looks as if

Apply-VMHostProfile -profile $data.profile -entity $VMHost -ApplyOnly -confirm:$false

isn't returning anything. 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

rxjoseph
Enthusiast
Enthusiast
Jump to solution

Hi LucD

 

As advised applied the command  you suggested but still getting the same error

#################################################################################

Starting esxi701.contoso.com.name

Name ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz MemoryUsageGB MemoryTotalGB Version
---- --------------- ---------- ------ ----------- ----------- ------------- ------------- -------
esxi701.contoso.com Maintenance PoweredOn 2 1915 4992 1.240 3.995 6.7.0
Getting Hash Table Answer File
Method invocation failed because [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl] does not contain a method named 'GetEnumerator'.
At line:25 char:4
+ If($AdditionalConfiguration){
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

#################################################################################

 

##CODE##

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

Apply-VMHostProfile -profile $data.profile -entity $VMHost -ApplyOnly -confirm:$false

#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 ‘*hostName*.name’ } {
$var += @{$_.Name = $data.hostName}
}
{$_.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
}

 

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is not what I said.
I just said that I had the impression that the command I mentioned wasn't returning anything.
You could check that.
First associate the HostyProfile, then apply it, and check if it returns a hash table.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

rxjoseph
Enthusiast
Enthusiast
Jump to solution

Hi LucD

Yes it's not returning anything 

 

PS C:\Windows\system32> Apply-VMHostProfile -profile $data.profile -entity $VMHost -ApplyOnly -confirm:$false


Name ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz MemoryUsageGB MemoryTotalGB Version
---- --------------- ---------- ------ ----------- ----------- ------------- ------------- -------
esxi701.contoso.com Maintenance PoweredOn 2 89 4992 1.197 3.995 6.7.0

 

Many thanks

RXJ

 

Reply
0 Kudos
rxjoseph
Enthusiast
Enthusiast
Jump to solution

Hi LucD

Correct it doesn't return any values

 

PS C:\Windows\system32> #Attach host profile to host
Apply-VMHostProfile -profile $data.profile -entity $VMhost -AssociateOnly -confirm:$false

Apply-VMHostProfile -profile $data.profile -entity $VMHost -ApplyOnly -confirm:$false


Name ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz MemoryUsageGB MemoryTotalGB Version
---- --------------- ---------- ------ ----------- ----------- ------------- ------------- -------
esxi701.contoso.com Maintenance PoweredOn 2 78 4992 1.153 3.995 6.7.0
esxi701.contoso.com Maintenance PoweredOn 2 78 4992 1.153 3.995 6.7.0

Many thanks

RXJ

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That would mean that in the HostProfile you are using there aren't any values that need to be entered.
Those, if they were there, would normally be returned in a hash table.

If your HostProfile has no values that need to be entered, then this script you are using doesn't really fit your situation.
If it is your intention that there are values that need to be entered per ESXi node, then you will have to review the HostProfile you are using.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

rxjoseph
Enthusiast
Enthusiast
Jump to solution

Hi LucD

 

Thanks a million got this sorted

it was my stateless profile playing up and now the script works

 

Many thanks

RXJ

Reply
0 Kudos