Skip to content

PowerShell OVF Helper

OVF Template for VMware Photon OS 3.0 (cloud-init)

The following PowerShell snippet can be used to deploy VMware Photon OS 3.0 (cloud-init) using PowerShell. The VMware.PowerCLI module is required to use the script.

  1. Copy the snippet to your favorite editor
  2. Change the path to your local OVA file
  3. Fill out the variables
  4. Connect to a vCenter Server using the Connect-VIServer command
  5. Run the script
ovf-Photon-OS-3.0-cloud-init.ps1:
$cloud_config=@"
#cloud-config
hostname: photon
fqdn: photon.virten.lab
timezone: Europe/Berlin
write_files:
  - path: /etc/systemd/network/10-static.network
    permissions: 0644
    content: |
      [Match]
      Name=eth0

      [Network]
      Address=192.168.x.x/24
      Gateway=192.168.x.x
      DNS=x.x.x.x
runcmd: 
  - systemctl restart systemd-networkd
  - tdnf update -y
ssh_authorized_keys:
  - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAB[...] user@domain
"@

$ovf = '.\photon-hw11-3.0-a383732.ova'
$ovfConfig = Get-OvfConfiguration $ovf
$ovfConfig.NetworkMapping.None.Value = ""  # Portgroup for Management Network
$VMName = ""                               # Virtual Machine Display Name
$vmhost = ""                               # ESXi Host to deploy the VM
$datastore = ""                            # Datastore to deploy the VM
$diskStorageFormat = "Thin"                # Thin or Thick provisionig of virtual disks

$vm = Import-VApp -Source $ovf -OvfConfiguration $ovfconfig -Name $VMName -VMHost (Get-VMHost -Name $VMHost) -Datastore $datastore -DiskStorageFormat $diskStorageFormat
$vm | Set-VM -NumCpu 2 -Confirm:$false |Out-Null
$vm | Set-VM -MemoryGB 4 -Confirm:$false  |Out-Null

$userDataBase64 = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($cloud_config))
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.VAppConfig = New-Object VMware.Vim.VmConfigSpec
$spec.VAppConfig.OvfEnvironmentTransport = @('com.vmware.guestInfo')
$spec.VAppConfig.Property = New-Object VMware.Vim.VAppPropertySpec[] (1)
$spec.VAppConfig.Property[0] = New-Object VMware.Vim.VAppPropertySpec
$spec.VAppConfig.Property[0].Operation = 'add'
$spec.VAppConfig.Property[0].Info = New-Object VMware.Vim.VAppPropertyInfo
$spec.VAppConfig.Property[0].Info.Category = "cloud-init"
$spec.VAppConfig.Property[0].Info.Id = 'user-data'
$spec.VAppConfig.Property[0].Info.Value = $userDataBase64

$vm.ExtensionData.ReconfigVM_Task($spec)
$vm | Start-VM

Please leave a comment when you have issues with the deployment. Additional feature requests are also welcome.

Confirmed Images:
photon-hw11-3.0-a383732.ova

<-- Back to PowerShell OVF Helper