Cannot bind argument to parameter 'Name' because it is an empty string

Getting an error when running this PowerShell script -

$SourceSubscription = "c3bffe7f-e643-4393-ae69-ab6e9fd0668f"
$TargetSubscription = "15c9a3ed-7da9-401a-8533-57039223ff04"


Clear
Select-AzSubscription -Subscription $TargetSubscription -ErrorAction Stop -Verbose

#read marketplace vm details from the json file

$Filex = '.\MarketplaceVMs.json'
$MarkVMs = Get-Content -Raw -Path $Filex | ConvertFrom-Json


foreach($MarkVM in $MarkVMs){
    
    #Common Parameters
    $resourceGroupName = $MarkVM.ResourceGroupName
    $location = $MarkVM.Location
    $virtualMachineName = $MarkVM.Name
    $virtualMachineSize = $MarkVM.HardwareProfile.VmSize            
    $nics = $MarkVM.NetworkProfile.NetworkInterfaces
    $caching = $MarkVM.StorageProfile.OsDisk.Caching


    #Create Marketplace VMs from managed disk
    if($MarkVM.StorageProfile.OsDisk.ManagedDisk){
        
        $osDiskName = $MarkVM.StorageProfile.OsDisk.Name  
        $disk = Get-AzDisk -ResourceGroupName $resourceGroupName -DiskName $osDiskName 

 
        $VirtualMachine = New-AzVMConfig -VMName $virtualMachineName -VMSize $virtualMachineSize 
        if($MarkVM.StorageProfile.OsDisk.OsType -eq 1){ 
            $VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -ManagedDiskId $disk.Id -CreateOption Attach -Caching $caching -Linux
            "`nCreating Linux configuration..."
            }
        else{ 
            $VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -ManagedDiskId $disk.Id -CreateOption Attach -Caching $caching -Windows
            "`nCreating Windows configuration..."
            }

        }


    #Create Marketplace VM from unmanaged disk
    if($MarkVM.StorageProfile.OsDisk.Vhd){
        
        $osDiskVhdUri = $MarkVM.StorageProfile.OsDisk.Vhd.Uri  
        $osDiskName = $MarkVM.StorageProfile.OsDisk.Name
   
        $VirtualMachine = New-AzVMConfig -VMName $virtualMachineName -VMSize $virtualMachineSize 
        if($MarkVM.StorageProfile.OsDisk.OsType -eq 1){ 
            $VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -Name $osDiskName -VhdUri $osDiskVhdUri -CreateOption Attach -Caching $caching -Linux  
            "`nCreating Linux configuration"        
        }
        else{
            $VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -Name $osDiskName -VhdUri $osDiskVhdUri -CreateOption Attach -Caching $caching -Windows
            "`nCreating Windows configuration"
        }
    }


     $VirtualMachine.Plan = New-Object -TypeName 'Microsoft.Azure.Management.Compute.Models.Plan'
     $VirtualMachine.Plan.Name = $MarkVM.Plan.Name
     $VirtualMachine.Plan.Product = $MarkVM.Plan.Product
     $VirtualMachine.Plan.Publisher = $MarkVM.Plan.Publisher
     Get-AzMarketplaceTerms -Publisher $VirtualMachine.Plan.Publisher -Product $VirtualMachine.Plan.Product -Name $VirtualMachine.Plan.Name | Set-AzMarketplaceTerms -Accept 
  
     foreach($nic in $nics){
            if($nic.Primary){
                $VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $nic.Id.Replace($SourceSubscription,$TargetSubscription) -Primary 
            }else{ 
                $VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $nic.Id.Replace($SourceSubscription,$TargetSubscription)
            }
        }

     $Virtualmachine | ConvertTo-Json
     New-AzVM -VM $VirtualMachine -ResourceGroupName $resourceGroupName -Location $location -Verbose
     'Virtual machine('+ $MarkVM.Name +') creation complete...'
    
}
`type or paste code here`

error that i am getting -

Get-AzMarketplaceTerms : Cannot bind argument to parameter 'Name' because it is an empty string.
At C:\Program Files\WindowsPowerShell\Modules\Az.MarketplaceOrdering\2.0.0\exports\ProxyCmdletDefinitions.ps1:537 char:9
+         $steppablePipeline.Begin($PSCmdlet)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-AzMarketplaceTerms_Get1], CmdletInvocationException
    + FullyQualifiedErrorId : Microsoft.Azure.PowerShell.Cmdlets.MarketplaceOrdering.Cmdlets.GetAzMarketplaceTerms_Get1
 
Set-AzMarketplaceTerms : Cannot bind argument to parameter 'Name' because it is an empty string.
At line:1 char:1
+ Get-AzMarketplaceTerms -Publisher $VirtualMachine.Plan.Publisher -Pro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Set-AzMarketplaceTerms], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Set-AzMarketplaceTerms

Some one please help me:)

Dheeman,
Welcome to the forum. :wave:t4:

Before we proceed … could you please go back, edit your question again and fix the formatting of your code and error messages?

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

Please check value of
$VirtualMachine.Plan.Name = $MarkVM.Plan.Name

Looks like there is some problem there.