Automation

 View Only
  • 1.  New-VM and return null

    Posted Apr 12, 2022 05:49 AM

    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?



  • 2.  RE: New-VM and return null

    Posted Apr 12, 2022 06:24 AM

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



  • 3.  RE: New-VM and return null

    Posted Apr 12, 2022 09:26 AM

    Write-Output $vm doesn't print anything.



  • 4.  RE: New-VM and return null

    Posted Apr 12, 2022 10:28 AM

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