Hello,
I’ve been working on this script to retrieve database information from Azure. I had to limit some of the functionality due to setting an Azure context to a specific subscription. Other posts show what I was trying to accomplish.
With this part of the script, I pull the resource group and sql server assigned to that resource group from a .csv file. Now, I’d like to assign the values from the .csv file to the ‘Get-AzSqlDatabase’ cmdlet which requires both values to return a SQL database.
Here’s what I had that was slightly working at one point until I change my approach:
[pre]
$scrubbed = Import-CSV $path | Where-Object{$.ResourceGroupName -and $.ServerName}
$dbs =
foreach ($s in $scrubbed) {
$db = Get-AzSqlDatabase -ServerName $ServerName -ResourceGroupName $ResourceGroupName -ErrorAction SilentlyContinue
[PSCustomObject]@{
$ResourceGroupName = $s.ResourceGroupName
$ServerName = $s.ServerName
}
}
[/pre]
Here’s the error:
[pre]
Get-AzSqlDatabase : Cannot validate argument on parameter ‘ServerName’. The argument is null or empty. Provide an argument that is not null or empty, and then try the command
again.
At line:3 char:49
- $db = Get-AzSqlDatabase -ServerName $ServerName -Resource …
-
- CategoryInfo : InvalidData: ( [Get-AzSqlDatabase], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure.Commands.Sql.Database.Cmdlet.GetAzureSqlDatabase
A null key is not allowed in a hash literal.
At line:5 char:17
- $ResourceGroupName = $s.ResourceGroupName
-
- CategoryInfo : InvalidOperation: (System.Collecti…deredDictionary:OrderedDictionary) , RuntimeException
- FullyQualifiedErrorId : InvalidNullKey
[/pre]
Thanks for your help!