PowerCLI | PowerShell Core 7 Preview

You are here:
← All Topics

The following PowerCLI are tested running fine with PowerShell Core 7 Preview

Install & Login to ESXi host

Run the following codes in VS Code with PowerShell Core 7 Preview selected

Install-Module VMware.PowerCLI

Import-Module VMware.PowerCLI
#Ignore the Cert warning if you are using the default selfsign Cert
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore

#Login to ESXi 6.7 Host
#LAB - ESXi 6.7 Host
$vCenter = ""
$User = "root"
$Password = "P@ssw0rd!@#$"

Connect-VIServer -Server $vCenter -User $User -Password $Password -WarningAction SilentlyContinue

Import OVF

Convert the OVA file to OVF using ovftool.exe as the OVA is the zip file for all *.ovf and *.vmdk files

#Import OVF
$OVA = "C:\Users\Administrator\Downloads\photon-hw13_uefi-3.0-9355405.ova"
$OVF = "C:\Users\Administrator\Downloads\photon-hw13_uefi-3.0-9355405.ovf"
$VM_Name = "PhotoOS"
$DataStore = "LOCAL"

#Convert OVA to OVF 
Set-Location “C:\Program Files\VMware\VMware OVF Tool”
.\ovftool.exe $OVA $OVF

#Import OVF with thin provisioning disk 
Import-VApp -Name $VM_Name -Datastore $DataStore -VMHost $vCenter -Source $OVF -DiskStorageFormat Thin

Provision a New VM

#Provision a New VM 
#Check Which Datastore for VM with "Get-Datastore"
#Check Port Group to use with "Get-VirtualPortGroup"
$VM_Net="VM Network"

$VM_Name = "Debian10"

#Provision VM
New-VM -Name $VM_Name `
–VMHost $VM_Host `
-Datastore $VM_DS `
-DiskGB 20 `
-DiskStorageFormat Thin `
-MemoryGB 2 `
-NumCpu 2 `
-NetworkName $VM_Net 

#Mount ISO File
Get-ChildItem -Recurse -Path vmstores:\ -Include *.iso | select name, Datastorefullpath
New-CDDrive -VM $VM_Name -ISOPath "[LOCAL] ISO/Debian10.2.iso" -StartConnected
#Change SCSI Type to ParaVirtual
Get-ScsiController -VM $VM_Name | Set-ScsiController -Type ParaVirtual 
#Change NetworkAdapter to VMXNET3 
Get-VM $VM_Name | Get-NetworkAdapter  | Set-NetworkAdapter -Type "vmxnet3" -NetworkName "porggroupname",.

#Verify VM
Get-VM -Name $VM_Name | Select Name, NumCpu,CoresPerSocket,MemoryGB,Version,ProvisionedSpaceGB,UsedSpaceGB
#Power ON VM 
Get-VM -Name $VM_Name | Start-VM

Leave a Comment