Cannot index into a null array. RRS feed

  • Question

  • Hi Guys,

    I am trying to create a script with task and one of the tasks is to create new azure vm. Everything is good until it comes to the part when it needs to create VMNic. 

    Monday, April 16, 2018 9:26 AM

All replies

  • Hi,

    New-AzureRmVM : Cannot validate argument on parameter 'VM'. The argument is null or empty. Provide an argument that is not null or

    You're using $VMConfig in your last command but its not defined anywhere in your script.

    Moreover, reading your script almost every variable CAN be empty at the time it should be used since you're not verifying properly if there is an value present or not.

    Monday, April 16, 2018 10:57 AM
  • Hi Toby,

    Thank you for your comment. The first command where it is failing is the New-AzureRmNetworkInterface and if it fails here in the beginning it will fail the last 2.  Can you please tell me why it fails at network card when I specified all variables? Shall I run with open array before New-AzureRmNetworkInterface

    $array = @()

    Or if you can tell me what to do in the last part to make this work
    Monday, April 16, 2018 11:15 AM
  • The problem is here: New-AzureRmNetworkInterface -Name $VMNIC -ResourceGroupName $ResourceGroup `
    -Location $Location -SubnetId $VNET.Subnets[0].Id -PublicIpAddressId $PublicIp.Id

    since this code does not create an array:

    $VNET = Read-Host 'Enter the existing VNET or create a new one'
    if(!$VNET) {
    Write-Host "VNET '$VNET' does not exist. To create a new one, please press enter.";
    $VNET = Read-Host "VNET NAME";
    Write-Host "Creating new VNET '$VNET'";

    Monday, April 16, 2018 11:18 AM
  • Do you know how to fix New-AzureRmNetworkInterface -Name $VMNIC -ResourceGroupName $ResourceGroup `-Location $Location -SubnetId $VNET.Subnets[0].Id -PublicIpAddressId $PublicIp.Id this command so that be array of I can write it in another way?
    Monday, April 16, 2018 11:37 AM
  • Hi Jimmy,

    Based on the current situation, I recommend using the actual values instead of variables for testing to see if the New-AzureRmNetworkInterface command works. The following article for your reference:

    Best Regards,

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, April 17, 2018 1:45 AM