PowerCLI

 View Only
  • 1.  Need to install ESXi 7.0.3 via powershell. Our physical server is Hpe ILO gen11.

    Posted 29 days ago

    Hi Experts,

    We are trying to install single ESXi 7.0.3 via powershell. Our physical server is Hpe ILO gen11. We tried a lot. But nothing works. We imported the HpeILOModule and we tried following steps this via powershell. 

    We  Power off the ILO server, Then unmount if any ILO was mounted, Then we Mount our customised ESXi ISO (which has the Boot.cfg which has local windows server IP and points to the ks.cfg URL), Then we changed the Boot order to CD/DVD, Then we are Power On the server. We are doing everthing via powershell. But the problem here is after the restart we should get the "Welcome to the Vmware ESXi Installation" screen. Thats the Expectation. But we are getting the blank PXE screen after we power on the server via powershell.

    When we tried the same steps manually its working and able to install it.

    ---------------------------------------------------

    Pre-req:
    created a 8080 firewall port
    Installed python file
    Established the Http port 8080 via python in Powershell console (Should not close the console)

    Created a ks.cfg with all the required inputs required for ESXi Installation (accept, Select the disk. Provide password, New esxi ip, subnet mask, gateway etc)
    keep the ks.cfg and customized ISO in the local server. 

    --------------------------------------

    Could someone please let me know what I have to do now, if you have right script. could you please provide it. Its will be so much helpful



    -------------------------------------------


  • 2.  RE: Need to install ESXi 7.0.3 via powershell. Our physical server is Hpe ILO gen11.

    Posted 28 days ago

    I have done exactly this so i should be able to help you get moving.

    I also power it off first.

    First thing, here is a snippet of my code

    $imageurl = "$sourceurl/$isoimage"
    Write-host "Mounting $($isoimage) on $newhost..." -ForegroundColor Cyan
    $isoresult = Mount-HPEiLOVirtualMedia -Connection $iloconnection -Device CD -ImageURL $imageurl

    I ended up setting up IIS on our script box and making sure NSX allowed 443 from the iLO.

    Part of custom ISO creation is to put a copy on the webserver.

    I use this to set it the system to boot from media on next reset

    #set to host to boot on media next boot
    Set-HPEiLOVirtualMediaStatus -Connection $iloconnection -VMBootOption BootOnNextReset -Device CD 

    I then power it on

    #Power on host
    $powerresult = Set-HPEiLOServerPower -Connection $iloconnection -Power On -Force
    I look forward to hearing back



  • 3.  RE: Need to install ESXi 7.0.3 via powershell. Our physical server is Hpe ILO gen11.

    Posted 27 days ago
    Edited by Leo0601 27 days ago
    @ChrisLeblanc

    Hi Chris,
     
    Sorry, I missed the notification. Just now noticed. 
     
    Thank you very much for your reply. If you help me to fix this, really it means a lot. 
     
    Let me explain briefly. 
     
    Environment:
     
    Hardware: HPE Gen11 (iLO 6)
    OS: VMware ESXi 7.0.3 (HPE Custom Image)
    Kickstart Source: Python HTTP service on Windows (port 8080) Following command I used the keep the HTTP session alive. I won't close this PowerShell screen - python -m http.server 8080. 
     
    Expectation:
    Fully unattended ESXi installation, where ks.cfg is hosted on the Windows server and boot.cfg in the ISO is modified as follows:
     
    kernelopt=runweasel ks=http://MyLocalWindowsServerIP_WhereIamTryingtoExecuteTheScript/ks.cfg
     
    Issue #1 - One-Time Boot Override
    When performed manually via the iLO Web UI, the server boots correctly from Virtual Media. However, when performed through PowerShell using the HPeILOModule, the server ignores the Virtual CD/DVD and boots to PXE instead. 
     
    Issue #2 - Kickstart Not Triggering
    Although the Kickstart file is accessible over HTTP (port 8080 confirmed), ESXi does not load it automatically and remains at the "Welcome to VMware ESXi installation" screen after modifying boot.cfg.
     
    We have no idea about the below things:
     
    Which boot.cfg is used during UEFI boot on Gen11 systems:
    EFI/BOOT/boot.cfg, or
    The boot.cfg in the ISO root?

    We observed Kickstart retrieval failures when modifying the EFI boot.cfg, Error states: File: (http://MyLocalWindowsServerIP_WhereIamTryingtoExecuteTheScript/ks.cfg) connection failed. Made 15 attempts. So we have added the http://MyLocalWindowsServerIP_WhereIamTryingtoExecuteTheScript/ks.cfg in Root/boot.cfg in ISO.

    Is there official VMware guidance for configuring Kickstart (ks.cfg) and modifying boot.cfg specifically for Gen11 UEFI systems?
    Requesting the correct iLO 6 (Gen11) PowerShell automation.
     
    Attached the ks.cfg, Boot.cfg and my main script as well file in the attachment.
     
    Now you might get some idea what I am trying to do.

    Could you please let me know now what I have to do. I will follow what you will suggest me.
     
    Thanks in advance.

    I look forward to hearing back
     
    Regards
    Leo

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Below is my Main script: 
     
    Import-Module HPEiLOCmdlets -ErrorAction Stop
     
    # --- CONFIGURATION (UPDATE THESE VALUES) ---
     
    # iLO Access Credentials
    $iLO_IP     = 'ILO_IP'        
    $iLO_User   = 'Username'         
    $iLO_Pass   = 'P@$$w0rd' 
    $iLO_Cred   = New-Object System.Management.Automation.PSCredential($iLO_User, (ConvertTo-SecureString $iLO_Pass -AsPlainText -Force))
     
    # Kickstart & ISO Configuration (CONFIRMED WORKING)
    $KickstartServerIP = "MyLocalWindowsServerIP_WhereIamTryingtoExecuteTheScript"
    $KickstartServerPort = 8080
    $ESXiImageName = "ESXi-ISO.iso"
     
    # Full URL to the ISO file on your Python web server (using Port 8080)
    $FullImageURL = "http://$KickstartServerIP`:$KickstartServerPort/$ESXiImageName"
    # -------------------------------------------
     
    Write-Host "Starting ESXi Deployment using HPEiLOCmdlets (v5.1.0.0 confirmed)." -ForegroundColor Cyan
    Write-Host "ISO Source URL: $FullImageURL" -ForegroundColor Cyan
     
    # 1. Connect to iLO
    Write-Host "`n1. Connecting to HPE iLO at $iLO_IP..."
    try {
        $iLOSession = Connect-HPEiLO -HostName $iLO_IP -Credential $iLO_Cred -DisableCertificateAuthentication -ErrorAction Stop
        Write-Host "Connection successful."
    }
    catch {
        Write-Error "Failed to connect to iLO. Check IP, credentials, network."
        exit 1
    }
     
    # 2. Clear existing Virtual Media and connect the new ISO
    Write-Host "`n2. Clearing old media and connecting new ISO image ($FullImageURL)..."
    try {
        # 2a. Action: Dismount previous media using the confirmed cmdlet. Use "CD" for the device.
        Write-Host "Attempting to disconnect previous virtual media using Dismount-HPEiLOVirtualMedia..."
        # Using a null URI to forcefully disconnect the current virtual media.
        Dismount-HPEiLOVirtualMedia -Connection $iLOSession -Device CD -ErrorAction SilentlyContinue
     
        # 2b. Action: Mount the new media using the confirmed cmdlet. Use "CD" for the device.
        Write-Host "Attempting to connect media using Mount-HPEiLOVirtualMedia..."
        # FINAL PARAMETER GUESS: Changed parameter from -ImageServerAddress to -Image
        Mount-HPEiLOVirtualMedia -Connection $iLOSession -Device CD -Image $FullImageURL -ErrorAction Stop
        
        Write-Host "ISO media successfully connected via URL." -ForegroundColor Green
    }
    catch {
        Write-Error "Failed to connect Virtual Media. Error: A parameter cannot be found that matches parameter name 'Image' or the connection failed. Check your iLO logs for more detail."
        
        Write-Host "--- CRITICAL TROUBLESHOOTING ---" -ForegroundColor Red
        Write-Host "The command is correct, but the parameter keeps failing. This almost always means the iLO cannot reach the source URL $FullImageURL." -ForegroundColor Red
        Write-Host "Please check the following:" -ForegroundColor Red
        Write-Host "  1. ACCESS THE ILO WEB INTERFACE." -ForegroundColor Yellow
        Write-Host "  2. MANUALLY ATTEMPT TO MOUNT THE ISO: Go to 'Virtual Media' and paste the URL $FullImageURL to see the specific error it reports." -ForegroundColor Yellow
        Write-Host "  3. CHECK NETWORK/FIREWALLS: Ensure there is a clear network path for the iLO to communicate with the web server  on port 8080." -ForegroundColor Yellow
        Write-Host "--------------------------------" -ForegroundColor Red
        
        Disconnect-HPEiLO -Connection $iLOSession -ErrorAction SilentlyContinue
        exit 1
    }
     
     
    # 3. Set the one-time boot order to Virtual CD-ROM (to boot from the connected ISO)
    Write-Host "`n3. Setting ONE-TIME Boot to Virtual CD-ROM to start installation..."
    try {
        # Action: Set one-time boot using the confirmed cmdlet and unambiguous parameter. Use "CD" for the boot source.
        Set-HPEiLOOneTimeBootOption -Connection $iLOSession -BootSourceOverrideTarget CD -ErrorAction Stop
        Write-Host "One-Time Boot set to Virtual Media (CD)."
    }
    catch {
        Write-Error "Failed to set One-Time Boot order. Error: $($_.Exception.Message)"
        Disconnect-HPEiLO -Connection $iLOSession -ErrorAction SilentlyContinue
        exit 1
    }
     
    # 4. Power cycle the server to initiate the boot process
    Write-Host "`n4. Power Cycling the server. Installation will begin shortly."
    Write-Host "The server will now boot from the ISO, which will read the updated boot.cfg (:8080) and find ks.cfg." -ForegroundColor Green
    try {
        Set-HPEiLOServerPower -Connection $iLOSession -Power Reset -ErrorAction Stop
        Write-Host "Server successfully reset."
    }
    catch {
        Write-Error "Failed to send reset command. Error: $($_.Exception.Message)"
    }
     
    finally {
        if ($iLOSession) {
            Write-Host "5. Disconnecting from iLO."
            Disconnect-HPEiLO -Connection $iLOSession -ErrorAction SilentlyContinue
        }
    }


    ------------------------------------------------------------------------------------------------------------------------------------

    Below is my ks.cfg

    # Unattended Kickstart Configuration
     
    # Accept screen
    vmaccepteula
     
    # Password
    rootpw --plaintext P@$$w0rd
     
    install --firstdisk --overwritevmfs
     
    # Configure the static management network.
    network --bootproto=static --device=vmnic0 --vlanid=21 --ip=17.XX.XX.XX --netmask=255.255.255.0 --gateway=17.XX.XX.1 --nameserver=17.XX.XX.1,8.8.8.8 --hostname=esxi-host01 --domain=yourdomain.local
     
    timezone --server --utc
     
    reboot
     
    # -----------------------------------------------------------
    # Post-Installation Commands 
    # -----------------------------------------------------------
    %firstboot --interpreter=busybox
     
    # 1. Disable IPv6 
    esxcli network ip set --ipv6-enabled=false
     
    # 2. Enable and start SSH service
    vim-cmd hostsvc/enable_ssh
    vim-cmd hostsvc/start_ssh
     
    # 3. Configure and start NTP client
    esxcli network firewall ruleset set --ruleset-id=ntpClient --enabled true
    esxcli system ntp set --servers="pool.ntp.org"
    /etc/init.d/ntpd restart
     
    # 4. Force a configuration save
    /sbin/auto-backup.sh
     
    # This closes the %firstboot section
    %post

    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Below is my boot.cfg (I have placed in root folder of ESXi ISO)

    bootstate=0
    title=Loading ESXi installer
    timeout=1
    prefix=
    kernel=/b.b00
    kernelopt=runweasel ks=http://MyLocalWindowsServerIP_WhereIamTryingtoExecuteTheScript:8080/ks.cfg
    modules=/jumpstrt.gz --- /useropts.gz --- /features.gz --- /k.b00 --- /uc_intel.b00 --- /uc_amd.b00 --- /uc_hygon.b00 --- /procfs.b00 --- /vmx.v00 --- /vim.v00 --- /tpm.v00 --- /sb.v00 --- /s.v00 --- /bnxtnet.v00 --- /bnxtroce.v00 --- /lsimr3.v00 --- /lpfc.v00 --- /amsd.v00 --- /amsdv.v00 --- /stage.v00 --- /payload.v00 --- /ilo.v00 --- /ilorest.v00 --- /sut.v00 --- /stage.v01 --- /i40en.v00 --- /iavmd.v00 --- /icen.v00 --- /igbn.v00 --- /ixgben.v00 --- /mft_oem.v00 --- /mft.v00 --- /nmlx4cor.v00 --- /nmlx4en.v00 --- /nmlx4rdm.v00 --- /nmlx5cor.v00 --- /nmlx5rdm.v00 --- /nmst.v00 --- /smartpqi.v00 --- /ssacli.v00 --- /qlnative.v00 --- /ionicen.v00 --- /qcnic.v00 --- /qedentv.v00 --- /qedf.v00 --- /qedi.v00 --- /qedrntv.v00 --- /qfle3.v00 --- /qfle3f.v00 --- /qfle3i.v00 --- /atlantic.v00 --- /brcmfcoe.v00 --- /elxiscsi.v00 --- /elxnet.v00 --- /irdman.v00 --- /iser.v00 --- /lpnic.v00 --- /lsi_msgp.v00 --- /lsi_msgp.v01 --- /lsi_msgp.v02 --- /mtip32xx.v00 --- /ne1000.v00 --- /nenic.v00 --- /nfnic.v00 --- /nhpsa.v00 --- /ntg3.v00 --- /nvme_pci.v00 --- /nvmerdma.v00 --- /nvmetcp.v00 --- /nvmxnet3.v00 --- /nvmxnet3.v01 --- /pvscsi.v00 --- /qflge.v00 --- /rste.v00 --- /sfvmk.v00 --- /vmkata.v00 --- /vmkfcoe.v00 --- /vmkusb.v00 --- /vmw_ahci.v00 --- /bmcal.v00 --- /crx.v00 --- /elx_esx_.v00 --- /btldr.v00 --- /esx_dvfi.v00 --- /esx_ui.v00 --- /esxupdt.v00 --- /tpmesxup.v00 --- /weaselin.v00 --- /esxio_co.v00 --- /loadesx.v00 --- /lsuv2_hp.v00 --- /lsuv2_in.v00 --- /lsuv2_ls.v00 --- /lsuv2_nv.v00 --- /lsuv2_oe.v00 --- /lsuv2_oe.v01 --- /lsuv2_oe.v02 --- /lsuv2_sm.v00 --- /native_m.v00 --- /trx.v00 --- /vdfs.v00 --- /vmware_e.v00 --- /vsan.v00 --- /vsanheal.v00 --- /vsanmgmt.v00 --- /tools.t00 --- /xorg.v00 --- /gc.v00 --- /imgdb.tgz --- /basemisc.tgz --- /resvibs.tgz --- /imgpayld.tgz
    build=7.0.3-0.125.23794027
    updated=0

    --------------------------------------------------------------------------------------

    Note:

    Below sequence works fine manually, So I have tried the exact sequence via Poweshell one by one. Everthing executed successfully but after the restart the server ignores the Virtual CD/DVD and boots to PXE instead.

     
    Import-Module HPEiLOCmdlets -ErrorAction Stop
     
    # iLO Access Credentials
    $iLO_IP     = 'ILO_IP'        
    $iLO_User   = 'Username'         
    $iLO_Pass   = 'P@$$w0rd' 
    $iLO_Cred   = New-Object System.Management.Automation.PSCredential($iLO_User, (ConvertTo-SecureString $iLO_Pass -AsPlainText -Force))
     
    # Kickstart & ISO Configuration (CONFIRMED WORKING)
    $KickstartServerIP = "MyLocalWindowsServerIP_WhereIamTryingtoExecuteTheScript"
    $KickstartServerPort = 8080
    $ESXiImageName = "ESXi-ISO.iso"
     
    # Full URL to the ISO file on your Python web server (using Port 8080)
    $FullImageURL = "http://$KickstartServerIP`:$KickstartServerPort/$ESXiImageName"
    # -------------------------------------------
     
     
    # 1. Connect to iLO
    Write-Host "`n1. Connecting to HPE iLO at $iLO_IP..."
    try {
        $iLOSession = Connect-HPEiLO -HostName $iLO_IP -Credential $iLO_Cred -DisableCertificateAuthentication -ErrorAction Stop
        Write-Host "Connection successful."
    }
    catch {
        Write-Error "Failed to connect to iLO. Check IP, credentials, network."
        exit 1
    }
     
     
     
    # --- 2) Power off the server ---
    $powerState = (Get-HPEiLOServerPower -Connection $iLOSession).Power
    if ($powerState -ne 'Off') {
        Write-Host "Server is currently ON. Powering off..."
        Set-HPEiLOServerPower -Connection $iLOSession -Power Off -Force | Out-Null
        # Wait until off
        for ($i=0; $i -lt 30; $i++) {
            Start-Sleep -Seconds 2
            if ((Get-HPEiLOServerPower -Connection $iLOSession).Power -eq 'Off') {
                break
            }
        }
        Write-Host "Server is now OFF."
    }
     
     
     
    # --- 3) Mount the ISO image ---
    Mount-HPEiLOVirtualMedia -Connection $iLOSession -Device CD -Image $FullImageURL -ErrorAction Stop
     
     
     
    # --- 4) Verify the ISO is mounted ---
    $ok = $false
    for ($i=0; $i -lt 10; $i++) {
        $status = Get-HPEiLOVirtualMediaStatus -Connection $iLOSession -Device CD
        if ($status.ImageInserted -eq 'Yes') {
            $ok = $true
            break
        }
        Start-Sleep -Seconds 2
    }
    if (-not $ok) {
        throw "Virtual media not inserted (iLO did not detect the ISO)."
    }
    Write-Host "Virtual media successfully inserted." -ForegroundColor Green
     
     
    # --- 5) Correct one-time boot for iLO6 ---
    $ok = $false
    try {
      Set-HPEiLOOneTimeBootOption -Connection $iLOSession `
        -BootSourceOverrideEnable Once `
        -BootSourceOverrideTarget UsbCd `
        -ErrorAction Stop | Out-Null
      $ok = true
    } catch {}
    if (-not $ok) {
      # some FW prefers 'CD'
      Set-HPEiLOOneTimeBootOption -Connection $iLOSession `
        -BootSourceOverrideEnable Once `
        -BootSourceOverrideTarget CD `
        -ErrorAction Stop | Out-Null
    }
     
    # --- 6) Power ON the server ---
    Write-Host "Powering on the server..."
    Set-HPEiLOServerPower -Connection $iLOSession -Power On | Out-Null

    ------------------------------------------------------------------------------------------------------------------------------------------

    -------------------------------------------



  • 4.  RE: Need to install ESXi 7.0.3 via powershell. Our physical server is Hpe ILO gen11.

    Posted 27 days ago

    here is what I have working for your issues

    Issue #1 - One-Time Boot Override
    When performed manually via the iLO Web UI, the server boots correctly from Virtual Media. However, when performed through PowerShell using the HPeILOModule, the server ignores the Virtual CD/DVD and boots to PXE instead. 
    I think I had tried the command you used and didn't get far. Actually I think I had tried both but ended up finding the one below on it's own worked for me.
    #set to host to boot on media next boot
    Set-HPEiLOVirtualMediaStatus -Connection $iloconnection -VMBootOption BootOnNextReset -Device CD 
    Try replacing what you have below with my command. After the first install pass, the media is ejected for me
    # Action: Set one-time boot using the confirmed cmdlet and unambiguous parameter. Use "CD" for the boot source.
        Set-HPEiLOOneTimeBootOption -Connection $iLOSession -BootSourceOverrideTarget CD -ErrorAction Stop

    For this

    Issue #2 - Kickstart Not Triggering
    Although the Kickstart file is accessible over HTTP (port 8080 confirmed), ESXi does not load it automatically and remains at the "Welcome to VMware ESXi installation" screen after modifying boot.cfg.
     
    We have no idea about the below things:
     
    Which boot.cfg is used during UEFI boot on Gen11 systems:
    EFI/BOOT/boot.cfg, or
    The boot.cfg in the ISO root?
    With Gen11 and UEFI as you mentioned, we now have to work in this path
    EFI/BOOT/boot.cfg
    below is the top of my boot.cfg, note I also have the ks.cfg in the same folder and the boot.cfg points to it. My ks.cfg is custom made from my script and I populate it with the IP info I gather early on from DNS for the new host. Its interesting you have your ks.cfg on the web. 

    bootstate=0
    title=Loading ESXi installer
    timeout=5
    prefix=
    kernel=/b.b00
    kernelopt=ks=cdrom:/EFI/BOOT/KS.CFG

    My first round with a UEFI only system was interesting.. it started installing via BIOS mode then it failed to see the HD after the first reboot.

    Do you use the same ISO each time and edit the ks.cfg file that the webserver provides?

    Don't worry btw about missing my post, it don't always have time to check either.

    -------------------------------------------



  • 5.  RE: Need to install ESXi 7.0.3 via powershell. Our physical server is Hpe ILO gen11.

    Posted 26 days ago

    @ChrisLeblanc

    Hi Chris,

    Thanks a lot for your response. I am so glad to see your reply.

    1) As you mentioned let me do the first change (I will use your command which was mentioned below)
    Set-HPEiLOVirtualMediaStatus -Connection $iloconnection -VMBootOption BootOnNextReset -Device CD 

    2) Do you use the same ISO each time and edit the ks.cfg file that the webserver provides?
    Yes, you are right. When have different Gen11 setups. So, we are going to use the same ISO. Also, the windows server also same which we are going to execute the script. We are planning to change only the Ks.cfg every time. Thats why we kept the ks.cfg in our windows server instead of ISO. 

    3) Oh okay. I got it. Thank you. So, we have to make the change in /EFI/BOOT/Boot.CFG instead of Root/boot.cfg
    Whenever we are making change in /EFI/BOOT/Boot.CFG, we are getting the below error

    File: (http://MyLocalWindowsServerIP/ks.cfg) connection failed. Made 15 attempts

    As you mentioned instead of keeping Ks.cfg in local server, We have to Embedded the Ks.cfg in ISO (/EFI/BOOT) and Also in the /EFI/BOOT/Boot.cfg we have to Point the ks.cfg (kernelopt=ks=cdrom:/EFI/BOOT/KS.CFG). 

    I am ready to keep the Ks.cfg in ISO as you mention, 

    If possible, could you please share your script? That will be so helpful and please let me know if any other changes I have to make in my environment. So, I can test everything in one shot and let you know for sure. Because in my script we have added the Http and Ks.cfg (Mentioned below variable in many places. Those needs to be removed., That's unnecessary confusion. 

    # Kickstart & ISO Configuration (CONFIRMED WORKING)
    $KickstartServerIP = "MyLocalWindowsServerIP_WhereIamTryingtoExecuteTheScript"
    $KickstartServerPort = 8080
    $ESXiImageName = "ESXi-ISO.iso"
    # Full URL to the ISO file on your Python web server (using Port 8080)
    $FullImageURL = "http://$KickstartServerIP`:$KickstartServerPort/$ESXiImageName"


    I am looking forward to hearing from you.

    Thanks again.

    Regards
    Leo.

    -------------------------------------------