PowerCLI

 View Only

 powercli New-VM SPEED CDROM NIC

Steven Maynard's profile image
Steven Maynard posted Oct 24, 2024 03:58 PM
Hello - 
 
I am getting close to being able to use my powercli script to build my gold images from a network wim.
 
vsphere 7.0 U2
powercli 13.3.0
Here is my process :
 
$pcliContext= Get-PowerCLIContext

function New-GoldImage {
    Param (
        [array]$vms
    )
 
    Set-Location $PSScriptRoot
    
    $vms | ForEach-Object -ThrottleLimit 10 -Parallel {
        
        Use-PowerCLIContext -PowerCLIContext $using:pcliContext -SkipImportModuleChecks
        $datastore = $_.Datastore
        $vmName = $_.HOSTNAME
        $guestID = $_.GuestID
        $MemoryGB = $_.MemoryGB
        $NumCpu = $_.NumCpu
        $ResourcePool = $_.ResourcePool
        Set-Location $PSScriptRoot
 
        "$vmName $guestID Mem:$memoryGB CPU:$NumCpu Datastore: $datastore"
 
        $getDataStore = Get-Datastore -Name $dataStore -Server $syncHash.vCenter
        
        $cdromISOPath = "[$getDataStore] .ISO/winpe.iso"
            
        $params = @{
            name = $vmName
            Server = $vCenter
            ResourcePool = $resourcePool
            DataStore = $datastore
            MemoryGB = $MemoryGB
            NumCpu = $NumCpu
            NetworkName = "dev-network"
            DiskStorageFormat = "EagerZeroedThick"
            DiskGB = "90"
            CD = $true
            GuestID = $guestID
            Confirm = $false
        }
            
        New-VM @params
 
        $newCdrom = @{
            'VM' = $vmName
            'IsoPath' = $cdromISOPath
            'StartConnected' = $true
            'Confirm' = $false
        }
        
        New-CDDrive @newCdrom
 
        if($error) {return $error}
    }
}
 
 
SPEED - When the vm is finished generating it takes about 4min. is this normal or slow? The UI is nearly instant.
CDROM - I always end up with 2 cdroms, can I simply edit the one it comes with?
CPU - can I also "enable virtualized cpu performance counters"?
NIC - the NIC defaults to E1000E. is it possible to default to VMXNET3?  From my reading this is set by vsphere based on the GuestID. Can this be altered? Part of my initial process relies on the network so this would be a huge help.
 
Thank you very much 
LucD's profile image
LucD

SPEED: where is this Use-PowerCLIContext function coming from?

CDROM: you should be able to use the one the New-VM comes with using the Get-CDRom and Set-CDRom cmdlets.
CPU: yes, but you will have to use the ReconfigVM method

$vm = Get-VM -Name MyVM

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.VPMCEnabled = $true
$vm.ExtensionData.ReconfigVM($spec)



NIC: the NIC type is, afaik, determined by the GuestID you select, and I'm afraid you can't change that. You can use the Set-NetworkAdapter cmdlet to change the type after the New-VM cmdlet