0

Working with GitHub project AzViz. I am attempting to run a PowerShell command to pull from a CSV file a list of multiple resource groups. It appears to pull in the groups but errors out with the following:

Get-AzResourceGroup : 'resourceGroupName' does not match expected pattern '^[-\w\._\(\)]+$'.

I am creating the function here:

$rsglist = Import-Csv C:\temp\azureinventory.csv

And running the following command:

Export-AzViz -ResourceGroup $rsglist -Theme dark -OutputFormat png -Show

You can see in this image that it is seemingly importing those resource groups:

enter image description here

And here is the result:

enter image description here

I suspect its telling me one of the group names is wrong, but going through all of the names, I don't see any not matching that pattern; I don't see any characters that would not be allowed.

I also understand this is a project and there may be issues within their code, just looking for any assistance. Thanks!

mklement0
  • 382,024
  • 64
  • 607
  • 775

1 Answers1

1

Export-AzViz's -ResourceGroup parameter expects an array of strings, whereas you're passing [pscustomobject] instances (which turn into unhelpful string representations), as output by Import-Csv.

Use the appropriate column (property) name from your CSV file to only pass the resource-group names, as strings; e.g., if the name information is in the Name column:

Export-AzViz -ResourceGroup $rsglist.Name -Theme dark -OutputFormat png -Show

Note: Accessing the .Name property on the collection (array) of objects stored in $rsglist in order to get the .Name property values of the elements of that collection is a convenient PowerShell feature called member-access enumeration.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • My pleasure, @rmittlerRenPSG. Re removing the header from a CSV file that contains only 1 column in order to read just _values_: You then don't need `Import-Csv` and can read the file with `Get-Content`. – mklement0 Aug 16 '21 at 15:45