2017-03-12 26 views
0

こんにちはすべて私は 'createSQLServer関数にサーバーのログイン資格情報を渡そうとしていますが、エラーを打ち続けています'Cannot process argument transformation on parameter 'creds'.userName''私は多くを試してみました。' param block 'しかし、ストールは立ち往生した。正しい方向へのプッシュは賞賛されるでしょう、歓声。資格情報を関数に渡す問題Azure Powershell

###### SQL SERVER LOGIN CREDENTIALS 
$userName = "aaron" 
$password = "Password_1234" 
$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force 
$creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $userName, $securePassword 

### SQL server names with resource group name appeneded 
$server1 = "sqlserver1" + $resGroup 
$serVerion = "12.0" 

function createSQLserver ([string]$server1,[string]$server2, [string]$server3, [System.Management.Automation.PSCredential]$creds,[string]$server1Location, [string]$server2Location, [string]$server3Location, [string]$resGroup, [string]$serVerion, [string]$userName, [string]$password, [SecureString]$securePassword) 
    { 
     #Create server 1(Server A) 
    <#check to see if server exists - It exists, $continue is created and passed to 
    if statement to append two random characters to name#> 
    Write-Host "Creating First SQL Server" 

     $sqlServer = New-AzureRmSqlServer -ServerName $server1 -SqlAdministratorCredentials $creds -Location $server1Location -ResourceGroupName $resGroup -ServerVersion $serVerion -ErrorVariable continue -ErrorAction SilentlyContinue 

    if ($continue) 
    { 
    do { 
     $server1 = $server1 + (rand) 
     $sqlServer = New-AzureRmSqlServer -ServerName $server1 ` 
    -SqlAdministratorCredentials $creds -Location $server1Location ` 
    -ResourceGroupName $resGroup -ServerVersion "12.0" -ErrorVariable continue -ErrorAction SilentlyContinue 
     } 
     until(!$continue) 

    Write-Host 'exists creating new' $server1 'Created' 
    }else{ 
    Write-Host $server1 ' Created' 
    } 
     Start-Sleep -s 2 
    } 


    createSQLserver $server1 $username $password $securePassword $creds $server1Location $resGroup $serVerion 

答えて

2

名前付きパラメータを使用する必要があります。

ここにあなたの最初のいくつかのパラメータの抜粋です:

... 
[string]$server1 
, 
[string]$server2 
, 
[string]$server3 
, 
[System.Management.Automation.PSCredential]$creds 
... 

そして、あなたはを使用していないので、あなたが関数呼び出しだから、

createSQLserver $server1 $username $password $securePassword ... 

に渡していた後のものパラメータの名前がの場合、それらの相対的な位置は、

です

私たちは何を学びましたか?

常に名前付きパラメータを使用してください。

:-)

あなたを整理する必要があり
createSQLserver -server1 $server1 -username $username -password $password -securePassword $securePassword 

関連する問題