Powershell ISE. Script that creates a VM from template inn the specified Datacenter RRS feed

  • Question

  • I need help solving this error

    New-VM : 07.05.2019 14.01.12 New-VM Template parameter: Could not find any of the objects specified by name.
    At C:\Powershell-scripts\Script that creates a VM from template inn the specified Datacenter.ps1:20 char:1
    + New-VM -Name $VMName -Template $VMtemplate -VMHost (get-vmhost)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (VMware.VimAutom...mplate Template:RuntimePropertyInfo) [New-VM], ObnRecordProcessingFailedException
        + FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

    This is the script

    # Virtual Center Details
    $server_address = ""
    $username = "RødtBord@vsphere.local"
    $password = "123"

    #TemplateName : Name of the Template which is used for the VM deployment
    #VMName  : The Name to be used for the new VM creation
    #VMtemplate : specifies what Datacenter the template is located in. And searches for templates whose names start with Martin

    $TemplateName = "Martin windows 10"
    $VMName = "MWindwos10test"
    $VMtemplate = "Get-Template -name Martin* -Datastore 'Host 44'"

    #Connecting to the VI Server

    Connect-VIServer -server $server_address -User $username -Password $password

    #Creates a new vm using a specified template

    New-VM -Name $VMName -Template $VMtemplate -VMHost (get-vmhost)

    #Starts the VM we just created with the template

    Get-VM -Name $VMName | Start-VM

    • Moved by Bill_Stewart Wednesday, September 4, 2019 9:46 PM Unanswerable drive-by question
    Tuesday, May 7, 2019 12:07 PM

All replies

  • You have to supply a VMName.

    Please ask the author of the script for help.  You will also do better if you read the instructions in the script.


    Tuesday, May 7, 2019 12:34 PM
  • I created it.
    Wednesday, May 8, 2019 6:56 AM
  • See this error:

    ObjectNotFound: (VMware.VimAutom...mplate Template:RuntimePropertyInfo) [New-VM],


    Wednesday, May 8, 2019 8:19 AM