CenturaBro
Enthusiast
Enthusiast

invoke-vmhostprofile -variable issue

Im trying to automate some of our non-autodeploy hosts in our environment....  was hoping to do this with an answer file as talked about from here: Automating ESXi Host Profile and Answer File with Powercli | NutzandBolts - An IT Systems Engineer E...

I'm having problems using the invoke-vmhostprofile though.   Even though that cmdlet works and i can apply it to a variable it is not showing me the key names i need. instead its just outputting the host I'm trying to run it on...  I also checked out the automating vmware book by lucd n friends and it shows the same commands as the blog above.

Heres the meat n potatoes (this is just a portion of the script):

______________________________________________________________________________________________________________

$answerfile = Import-CSV "C:\Scripts\answerfile.csv"

$VMhost = Get-VMhost

foreach($data in $answerfile) {

   

    $TargetHost = $VMhost | where {$_.Name -eq  $data.hostname}

    if ($TargetHost.State -eq "Connected"){

     Set-VMHost -VMHost $TargetHost -State Maintenance -Evacuate

     }

   

    $AdditionalConfiguration =   invoke-VMHostProfile -profile $data.profile -entity $TargetHost -ApplyOnly -confirm:$false

______________________________________________________________________________________________________________

if i do

$additionalconfiguration | Select name

It will give me the same output as if i called $targethost  and i need the key names

any help would be great.

thanks!

0 Kudos
8 Replies
LucD
Leadership
Leadership

Working with Host Profiles have changed.
Try like this to get the required input

$hpName = 'Test'

$esxName = 'MyEsx'

$esx = Get-VMHost -Name $esxName

$hp = Get-VMHostProfile -Name $hpName

Get-VMHostProfileRequiredInput -VMHost $esx -Profile $hp


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

0 Kudos
CenturaBro
Enthusiast
Enthusiast

So if I'm reading this right, if the host already has all the right keys populated as things like vMotion / mgmt  ip/subnet, get-vmhostprofilerequiredinput will return nothing in which case you're good to remediate?

0 Kudos
LucD
Leadership
Leadership

No, that is what Test-VMHostProfileCompliance does.

The Get-VMHostProfileRequiredInput cmdlet compares the host profile against a hash table (not provided, hence empty in my earlier example), and returns the missing values (in the hash table).

If this returns nothing, then it could be that the host profile does not prompt for any values, or that there is an issue with this cmdlet.


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

0 Kudos
CenturaBro
Enthusiast
Enthusiast

Tested with newest powershell / powercli on a 5.5 and 6.5 environment and got the same result.  If i run that command it returns blank.  Host has a profile attached, but it is being applied via the cluster.  Don't think that should make a difference though.

The host profile does prompt for Vmk port configurations which is what i was hoping to automate.

Ill try to do some more testing.

0 Kudos
LucD
Leadership
Leadership

Besides the VMK (is that on a VSS or VDS), do you have other prompt fields in your Host Profile?


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

0 Kudos
CenturaBro
Enthusiast
Enthusiast

VMK are on VSS at the moment.  only running VDS for portgroups.

No other prompt fields.

Even though it looks like the cmdlet isnt working, i got the script to work with some workarounds.

So in 6.5 it looks like most of the VMK fields get auto-populated.  The only other field that would definitely need input is the AD join.  I was able to get Authentication Proxy to work with the hosts to remove that. Got a backup of host configs and host profiles just in case but it looks like its working good now.

0 Kudos
karps
Contributor
Contributor

Hey LucD,
I am seeing the same problem with the Get-VMHostProfileRequiredInput cmdlet. I am running it against the VCSA 6.5U1 and the ESXi host in 6.0 U3. My Powercli build is 6.5.3. I hav also tried this with PowerCLI 6.3 R1, same results. 

My host profile was also attached at the cluster level, but attaching it to the host directly didn't change anything. My host profile requires input for vmk ports on the vDS.

I also tried the below commands from the nutzandbolts blog and am getting the below results

$AdditionalConfiguration = Apply-VMHostProfile -profile $profilname -entity $VMHost -ApplyOnly -confirm:$false
$AdditionalConfiguration.GetEnumerator()| fl

Method invocation failed because [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl] does not contain a method named 'GetEnumerator'.

At line:1 char:1
+ $AdditionalConfiguration.GetEnumerator()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

Should we log a case with GSS for this?

Method invocation failed because [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl] does not contain a method named 'GetEnumerator'.
At line:1 char:1
+ $AdditionalConfiguration.GetEnumerator()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
0 Kudos
nicholas1982
Hot Shot
Hot Shot

Getting strange issues with powercli and host profiles too. I resorted to a different method not sure if it will help you Hash Table from CSV not working for Invoke-VMHostProfile

Nicholas VCP6
0 Kudos