Azure/Powershell: Checking to see if a SQL Server exists -


i'm coming c# background, , first foray powershell. i'm trying write powershell script whole bunch of stuff in azure, among them:

  • check see if sql server instance exists
    • create server (using new-azurermsqlserver) if not
  • create new db on server
  • ... , other stuff

my first problem if server exists, don't need create it; can go directly db creation. however, can't seem make work.

i tried get-azurermsqlserver, errors out if can't find server i'm looking for. finally, went function return $true if found , $false if not:

function check-for-server {     param(         [parameter(mandatory=$true)]         [string]         $servername     )      if (test-azurename -name $servername)     {         return $false     }     else     {         return $true     } } 

here's problem: i'm getting following error:

test-azurename : parameter set cannot resolved using specified named parameters.
@ c:\src\powershell\test.ps1:10 char:9
+ if (test-azurename -name $servername)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ categoryinfo : invalidargument: (:) [test-azurename], parameterbindingexception
+ fullyqualifiederrorid : ambiguousparameterset,microsoft.windowsazure.commands.cloudservice.testazurenamecommand

does know how around this? google absolutely no help, @ least far test-azurename particular error message. thought of trying 1 of -service/servicebusname/storage/website arguments, i'm not sure applicable here. or if it's relevant -- error message doesn't appear indicate i'm missing parameter, 1 provided somehow bad.

oh, , if helps, here's call check-for-server:

$sqlservername = "test_db_server" check-for-server -servername $sqlservername 

thanks!

$serverinstance = get-azurermsqlserver -servername $servername -resourcegroupname $resourcegroupname -erroraction silentlycontinue if ($serverinstance) { stuff } else { other stuff } 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -