Hi Trying to run below script but getting the error message.
\nIt is working fine with foreach-object but getting the error message with foreach($VMNAME in $VMCSV)<\/p>\n
$VMCSV=Import-csv 'D:\\17-10-20\\Startvm.csv'\nforeach($VMNAME in $VMCSV){\n$Name = $VMNAME.VMNAME\n$RGN = $VMNAME.RGN\n$Location = $VMANME.Location\n$VMLIST = Get-azurermvm -status -Name $Name -ResourceGroupName $RGN\n$Status = $VMLIST.Statuses[1].DisplayStatus\n}\n<\/code><\/pre>","upvoteCount":3,"answerCount":15,"datePublished":"2020-10-17T06:25:37.000Z","author":{"@type":"Person","name":"pktech","url":"https://community.spiceworks.com/u/pktech"},"suggestedAnswer":[{"@type":"Answer","text":"
Advertisement
Hi Trying to run below script but getting the error message.
\nIt is working fine with foreach-object but getting the error message with foreach($VMNAME in $VMCSV)<\/p>\n
$VMCSV=Import-csv 'D:\\17-10-20\\Startvm.csv'\nforeach($VMNAME in $VMCSV){\n$Name = $VMNAME.VMNAME\n$RGN = $VMNAME.RGN\n$Location = $VMANME.Location\n$VMLIST = Get-azurermvm -status -Name $Name -ResourceGroupName $RGN\n$Status = $VMLIST.Statuses[1].DisplayStatus\n}\n<\/code><\/pre>","upvoteCount":3,"datePublished":"2020-10-17T06:25:37.000Z","url":"https://community.spiceworks.com/t/unable-to-run-the-script-using-foreach/779149/1","author":{"@type":"Person","name":"pktech","url":"https://community.spiceworks.com/u/pktech"}},{"@type":"Answer","text":"
Advertisement
well… what is the error?<\/p>\n
how do you have it written with foreach-object?<\/p>","upvoteCount":0,"datePublished":"2020-10-17T07:35:44.000Z","url":"https://community.spiceworks.com/t/unable-to-run-the-script-using-foreach/779149/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Hi Support,<\/p>\n
Please find the error message in below.<\/p>\n
Cannot validate argument on parameter ‘Name’. The argument is null or empty. Provide an argument that is not null or empty, and then try the
\ncommand again.
\nAt line:5 char:32<\/p>","upvoteCount":0,"datePublished":"2020-10-17T07:47:27.000Z","url":"https://community.spiceworks.com/t/unable-to-run-the-script-using-foreach/779149/3","author":{"@type":"Person","name":"pktech","url":"https://community.spiceworks.com/u/pktech"}},{"@type":"Answer","text":"
support…?<\/p>\n
What columns do you have in your CSV? Do you have a column called ‘vmname’ and ‘RGN’?<\/p>\n
Does every row in the CSV have a value?<\/p>\n
$VMCSV = Import-csv 'D:\\17-10-20\\Startvm.csv'\nforeach($VM in $VMCSV){\n $VMLIST = Get-azurermvm -Name $vm.vmname -ResourceGroupName $vm.RGN -status\n $Status = $VMLIST.Statuses[1].DisplayStatus\n $status\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2020-10-17T08:00:56.000Z","url":"https://community.spiceworks.com/t/unable-to-run-the-script-using-foreach/779149/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"Hi Neally,<\/p>\n
Thanks.<\/p>\n
Script is running fine but also showing the error message.<\/p>\n
PS C:\\WINDOWS\\system32> $VMCSV = Import-csv 'D:\\17-10-20\\Startvm.csv'\nforeach($VM in $VMCSV){\n $VMLIST = Get-azurermvm -Name $vm.vmname -ResourceGroupName $vm.RGN -status\n $Status = $VMLIST.Statuses[1].DisplayStatus\n $status\n}\nVM deallocated\nVM running\n\n<\/code><\/pre>\nError Message:\n<\/code><\/pre>\nGet-AzureRmVM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.\nAt line:3 char:35\n+ $VMLIST = Get-azurermvm -Name $vm.vmname -ResourceGroupName $vm.R ...\n+ ~~~~~~~~~~\n + CategoryInfo : InvalidData: (:) [Get-AzureRmVM], ParameterBindingValidationException\n + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure.Commands.Compute.GetAzureVMCommand\n\n<\/code><\/pre>\n\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2020-10-17T08:08:13.000Z","url":"https://community.spiceworks.com/t/unable-to-run-the-script-using-foreach/779149/5","author":{"@type":"Person","name":"pktech","url":"https://community.spiceworks.com/u/pktech"}},{"@type":"Answer","text":"can you please post a sanitized version of your CSV ?<\/p>\n
again, are all the row populated?<\/p>\n
it is basically saying there is a blank value.<\/p>","upvoteCount":0,"datePublished":"2020-10-17T08:26:59.000Z","url":"https://community.spiceworks.com/t/unable-to-run-the-script-using-foreach/779149/6","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Hi Neally,<\/p>\n
CSV is correct but i don’t know why it’s showing the error message.<\/p>\n
RGN,VMNAME,Location,Subscriptionid\nlab_RG,dcserver,East US,69689b9511111111111111\nLAB_RG,win-2019,East US,98654b9555555555555555\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2020-10-17T08:41:39.000Z","url":"https://community.spiceworks.com/t/unable-to-run-the-script-using-foreach/779149/7","author":{"@type":"Person","name":"pktech","url":"https://community.spiceworks.com/u/pktech"}},{"@type":"Answer","text":"looks rights.<\/p>\n
how does your code for the foreach-object look like that works?<\/p>","upvoteCount":0,"datePublished":"2020-10-17T08:43:27.000Z","url":"https://community.spiceworks.com/t/unable-to-run-the-script-using-foreach/779149/8","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Hi Neally,<\/p>\n
Yes, I am also checking why getting the error message.<\/p>\n
Thanks for support<\/p>","upvoteCount":0,"datePublished":"2020-10-17T08:51:33.000Z","url":"https://community.spiceworks.com/t/unable-to-run-the-script-using-foreach/779149/9","author":{"@type":"Person","name":"pktech","url":"https://community.spiceworks.com/u/pktech"}},{"@type":"Answer","text":"
can you post the working code?<\/p>\n
im super positive it has to do with your input file, rather than the foreach loop.<\/p>\n
does it give you that error for every single row?<\/p>","upvoteCount":0,"datePublished":"2020-10-17T08:54:43.000Z","url":"https://community.spiceworks.com/t/unable-to-run-the-script-using-foreach/779149/10","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
what if you run it like so, do you see any blank values?<\/p>\n
$VMCSV = Import-csv 'D:\\17-10-20\\Startvm.csv';\n\nforeach($VM in $VMCSV){\n write-output \"'$($vm.vmname)'\"\n write-output \"'$($vm.rgn)'\"\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2020-10-17T08:58:55.000Z","url":"https://community.spiceworks.com/t/unable-to-run-the-script-using-foreach/779149/11","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"Hi Neally,<\/p>\n
No, Output is correct.<\/p>","upvoteCount":0,"datePublished":"2020-10-17T09:03:52.000Z","url":"https://community.spiceworks.com/t/unable-to-run-the-script-using-foreach/779149/12","author":{"@type":"Person","name":"pktech","url":"https://community.spiceworks.com/u/pktech"}},{"@type":"Answer","text":"
Looks like you had similar problem here:<\/p>\n