2017-03-12 12 views
0

안녕하세요. 'createSQLServer 함수에 서버 로그인 자격 증명을 전달하려고하지만 오류가 계속 발생합니다. 'Cannot process argument transformation on parameter 'creds'.userName'''param 블록 '으로 시도해 보았습니다. 하지만 stull stuck. 올바른 방향으로 밀고 가면 칭찬받을 것입니다.기능에 자격 증명을 전달하는 문제 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 ... 

따라서 함수 호출에 전달하는 다음 사람 : 여기

은 처음 몇 매개 변수의 조각이다 매개 변수의 이름이
인 경우 상대 순위 위치를 사용합니다. 즉,

param | value 
---------+---------------- 
$server1 | $server1 
$server2 | $username 
$server3 | $password 
$creds | $securePassword 

그래서 우리는 무엇을 배웠는가?

항상 명명 된 매개 변수를 사용하십시오!

createSQLserver -server1 $server1 -username $username -password $password -securePassword $securePassword 

:-)

을 분류한다