none
Read CSV and find azurevm using Get-AzureRMVM -Name RRS feed

  • Question

  • Hello people,

    I have an list of Azure VM and I want checking if this VM still available on the environment.

    I try to use this script:

    $vms = import-csv -Path C:\temp\vm.csv
    $vms | ForEach-Object { Get-AzureRmVM -Name $vms.Name}

    But when I run this, return the error:

    Get-AzureRmVM : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Name'. Specified method is not supported.
    At line:2 char:54
    + $vms | ForEach-Object -Process { Get-AzureRmVM -Name $vms.Name}
    +                                                      ~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Get-AzureRmVM], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Azure.Commands.Compute.GetAzureVMCommand
     

    Please, can anyone help me with this?

    Tks

    Wednesday, September 12, 2018 7:16 PM

All replies

  • I the pipeline use "$_".


    \_(ツ)_/

    Wednesday, September 12, 2018 7:27 PM
    Moderator
  • Hi,

    Thanks for your question.

    I agree with jrv's reply.

    $vms = import-csv -Path C:\temp\vm.csv
    ForEach($vm in $vms) { Get-AzureRmVM -Name $vm.Name}
    If you want to use pipeline, you should use "$_". If you don't use pipeline, you can use the example above.

    Best Regards,

    Lee


    Just do it.

    Thursday, September 13, 2018 5:52 AM
    Moderator