I have a script that reads info from a csv file to build a VM which has always worked in the past but....
The script still builds the VM as it is supposed to without problem, but running set-vm and start-vm commands fail after with these errors. In this case I built a VM named PRDV2N3.
Any ideas???
Get-VM : 3/7/2019 11:49:04 AM Get-VM VM with name 'PRDV2N3 ' was not found using the specified filter(s).
At C:\temp\keep.ps1:24 char:1
+ Get-VM -Name $($line.name) | Set-VM -memoryGB $($line.memory) -NumCpu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
start-vm : 3/7/2019 11:49:04 AM Start-VM Could not find VirtualMachine with name 'PRDV2N3 '.
At C:\temp\keep.ps1:26 char:1
+ start-vm -vm $($line.name) -confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (PRDV2N3 :String) [Start-VM], VimException
+ FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_ObjectNotFound,VMware.VimAutomation.ViCore.Cmdle
ts.Commands.StartVM
start-vm : 3/7/2019 11:49:04 AM Start-VM Value cannot be found for the mandatory parameter VM
At C:\temp\keep.ps1:26 char:1
+ start-vm -vm $($line.name) -confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Start-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.StartVM
VM Build Script
$ScriptRoot = Split-Path $MyInvocation.MyCommand.Path
$csvfile = "$ScriptRoot\vmbuilder.csv"
$vms2deploy = Import-Csv -Path $csvfile
#For every line in the csv variable do something:
foreach ($line in $vms2deploy) {
Get-OSCustomizationSpec -Name $($line.oscust) | New-OSCustomizationSpec -name "$($line.oscust)_$($line.name)"
Get-OSCustomizationSpec "$($line.oscust)_$($line.name)"| Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $($line.ip) -SubnetMask $($line.mask) -DefaultGateway $($line.gw) -Dns $($line.dns1),$($line.dns2)
$vmhost = get-cluster $($line.cluster) | get-vmhost -state connected | Get-Random
new-vm -name $($line.name) -template $($line.template) -vmhost $vmhost -oscustomizationspec "$($line.oscust)_$($line.name)" -datastore $($line.datastore) -location $($line.folder) -DiskStorageFormat thin
Get-VM -Name $($line.name) | Set-VM -memoryGB $($line.memory) -NumCpu $($line.cpu) -confirm:$false
start-vm -vm $($line.name) -confirm:$false
Remove-OSCustomizationSpec "$($line.oscust)_$($line.name)" -confirm:$false
}