VMware Cloud Community
m_pahlevanzadeh
Enthusiast
Enthusiast

New-VM and return null

I ran my powershell with powershell 7.2.1-1 in ubuntu and vCenter 7.0.2 and last SDK of VMWare. It was ran successfuly. Now I run my script in powershell 7.2.1-1 in ubuntu and vCenter 6.0.0 But I get the following error:

New-VM: /installer.ps1:125
Line |
125 | $vm = New-VM -Template $template -VMHost $esx -Name $myVM -Datastore …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 04/12/2022 05:39:47 New-VM

After $vm line, I run the following line :

Get-HardDisk -vm $vm |Set-HardDisk -CapacityGB 25 -Confirm:$false

And get the following error:

Get-HardDisk: Cannot validate argument on parameter 'VM'. The argument is null. Provide a valid value for the argument, and then try running the command again.

How can I fix this error in my script? Is it related to vcenter version?

Tags (1)
0 Kudos
3 Replies
LucD
Leadership
Leadership

And what do you actually have in $vm?
Is the New-VM returning any errors?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
m_pahlevanzadeh
Enthusiast
Enthusiast

Write-Output $vm doesn't print anything.

Tags (1)
0 Kudos
LucD
Leadership
Leadership

That means the New-VM didn't work.
There should be an error message


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos