Automation

 View Only
  • 1.  invoke-vmhostprofile -variable issue

    Posted Oct 27, 2017 01:04 AM

    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 Experiences

    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!



  • 2.  RE: invoke-vmhostprofile -variable issue

    Posted Oct 27, 2017 06:49 AM

    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



  • 3.  RE: invoke-vmhostprofile -variable issue

    Posted Oct 27, 2017 04:32 PM

    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?



  • 4.  RE: invoke-vmhostprofile -variable issue

    Posted Oct 27, 2017 06:44 PM

    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.



  • 5.  RE: invoke-vmhostprofile -variable issue

    Posted Oct 27, 2017 08:43 PM

    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.



  • 6.  RE: invoke-vmhostprofile -variable issue

    Posted Oct 28, 2017 01:31 AM

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



  • 7.  RE: invoke-vmhostprofile -variable issue

    Posted Oct 29, 2017 05:04 AM

    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.



  • 8.  RE: invoke-vmhostprofile -variable issue

    Posted Nov 15, 2017 10:28 PM

    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


  • 9.  RE: invoke-vmhostprofile -variable issue

    Posted Nov 16, 2017 03:33 AM

    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