locked
The term '-location' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again RRS feed

  • Question

  • Dear all,

    I am trying to add additional network interface to my AzureVM through Powershell script. Now I am experiencing the following error:

    " The term '-location' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name or if a path was included, verify that the path is correct and try again ". I get this when I try to execute the following command in my script:

    "Add-AzureRmVMNetworkInterface -VM $vm -Id $nicId | Update-AzureRmVM -ResourceGroupName $rg | -location $loc". When I take the "Location" out of my script, it says "Location can not be NULL". Can anyone please help me out with this issue? THanks in advance!

    Regards,

    Kerim Tupkovic

    Thursday, August 3, 2017 8:02 AM

All replies

  • You should format your code as code here in the forum. With the code you posted seems something wrong. It does not make sense to pipe something to a paramter. And the cmdlet you're using (Update-AzureRmVM) does not have a paramter -location!?

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Thursday, August 3, 2017 9:42 AM
  • Hi!

    Thanks for the reply...this is the code I am using. Although it is only part of code that isn't working:

    $nicId = (Get-AzureRmNetworkInterface -ResourceGroupName $rg -Name $nic02).Id
    Add-AzureRmVMNetworkInterface -VM $vm -Id $nicId | Update-AzureRmVM -ResourceGroupName $rg | -location $loc

    $vnet = Get-AzureRmVirtualNetwork -Name $vNetName -ResourceGroupName $resourceGroupName
    $subnetId = $vnet.Subnets | Where-Object -FilterScript {$_.Name -eq $subnetName}
    $nic = New-AzureRmNetworkInterface `
                 -ResourceGroupName $resourceGroupName `
                 -Name $nicName `
                 -Location $location `
                 -SubnetId $subnetId
    $nicId = (Get-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName -Name $nicName).Id
    Add-AzureRmVMNetworkInterface -VM $vm -Id $nicId | Update-AzureRmVM -ResourceGroupName resourceGroupName | -location $loc

    Thursday, August 3, 2017 12:09 PM
  • There is an option on the edit bar to format code as code. That would preserve line breaks, indentions and so on ... 

    You should ask the author of the code to debug it for you. I assume this code cannot work this way.


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Thursday, August 3, 2017 1:39 PM
  • Error message is self-explanatory as if you look at the last lines of your code

    Add-AzureRmVMNetworkInterface -VM $vm -Id $nicId |

    Update-AzureRmVM -ResourceGroupName resourceGroupName | -location $loc


    You are piping over to -location, there is no such cmdlet, so you are missing the verb in front of -location.


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    • Proposed as answer by jrv Thursday, August 3, 2017 4:46 PM
    Thursday, August 3, 2017 3:04 PM
  • Yea I've changed my script in identical as yours and it works like a charm now! Just saw your post, thanks for it!
    Tuesday, August 8, 2017 9:43 AM
  • Hi KerimTupkovic,

    If the information provided was helpful,please "mark it as answer" to help other community members find the helpful reply quickly.

    Best Regards,

    Candy


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

    Wednesday, August 30, 2017 8:57 AM