New-AzureSqlDatabaseServerContext
建立伺服器連接內容。
注意
本文件中參考的 Cmdlet 用於管理使用 Azure Service Manager(ASM) API 的舊版 Azure 資源。 建立新的資源時,不建議使用此舊版 PowerShell 模組,因為 ASM 已排定淘汰。 如需詳細資訊,請參閱 Azure Service Manager 淘汰。
Az PowerShell 模組是使用 PowerShell 管理 Azure Resource Manager (ARM) 資源的建議 PowerShell 模組。
語法
New-AzureSqlDatabaseServerContext
-ServerName <String>
-Credential <PSCredential>
[-Profile <AzureSMProfile>]
[<CommonParameters>]
New-AzureSqlDatabaseServerContext
[-ServerName <String>]
-ManageUrl <Uri>
-Credential <PSCredential>
[-Profile <AzureSMProfile>]
[<CommonParameters>]
New-AzureSqlDatabaseServerContext
-ServerName <String>
[-UseSubscription]
[-SubscriptionName <String>]
[-Profile <AzureSMProfile>]
[<CommonParameters>]
New-AzureSqlDatabaseServerContext
-FullyQualifiedServerName <String>
-Credential <PSCredential>
[-Profile <AzureSMProfile>]
[<CommonParameters>]
New-AzureSqlDatabaseServerContext
-FullyQualifiedServerName <String>
[-UseSubscription]
[-SubscriptionName <String>]
[-Profile <AzureSMProfile>]
[<CommonParameters>]
Description
New-AzureSqlDatabaseServerContext Cmdlet 會建立 Azure SQL 資料庫 伺服器連線內容。 使用 SQL Server 驗證,使用指定的認證建立 SQL 資料庫 伺服器的連線內容。 您可以依名稱、完整名稱或網址指定 SQL 資料庫 伺服器。 若要取得認證,請使用 Get-Credential Cmdlet,提示您指定使用者名稱和密碼。
使用 New-AzureSqlDatabaseServerContext Cmdlet 搭配憑證式驗證,使用指定的 Azure 訂用帳戶數據,建立與指定之 SQL 資料庫 伺服器的連線內容。 您可以依名稱或完整名稱指定 SQL 資料庫 伺服器。 您可以將訂用帳戶數據指定為參數,也可以從目前的 Azure 訂用帳戶擷取。 使用 Select-AzureSubscriptionhttps://msdn.microsoft.com/library/windowsazure/jj152833.aspx Cmdlet 來選取目前的 Azure 訂用帳戶。
範例
範例 1:使用 SQL Server 驗證建立內容
PS C:\> $Credential = Get-Credential
PS C:\> $Context = New-AzureSqlDatabaseServerContext -ServerName "lpqd0zbr8y" -Credential $Credential
PS C:\> $Database17 = New-AzureSqlDatabase -ConnectionContext $Context -DatabaseName "Database17" -MaxSizeGB 50 -Collation "SQL_Latin1_General_CP1_CI_AS"
此範例使用 SQL Server 驗證。
第一個命令會提示您輸入伺服器管理員認證,並將認證儲存在 $Credential 變數中。
第二個命令會使用 $Credential 連接到名為 lpqd0zbr8y 的 SQL 資料庫 伺服器。
最後一個命令會在伺服器上建立名為 Database17 的資料庫,該資料庫是$Context內容中的一部分。
範例 2:使用憑證式驗證建立內容
PS C:\> $SubscriptionId = <Subscription ID>
PS C:\> $Thumbprint = <Certificate Thumbprint>
PS C:\> $Certificate = Get-Item "Cert:\CurrentUser\My\$Thumbprint"
PS C:\> Set-AzureSubscription -SubscriptionName "Subscription07" -SubscriptionId $SubscriptionId -Certificate $Certificate
PS C:\> Select-AzureSubscription -SubscriptionName "Subscription07"
PS C:\> $Context = New-AzureSqlDatabaseServerContext -ServerName "lpqd0zbr8y" -UseSubscription
此範例會使用憑證型驗證。
前兩個命令會將值指派給$SubscriptionId和$Thumbprint變數。
第三個命令會取得$Thumbprint指紋所識別的憑證,並將它儲存在$Certificate中。
第四個命令會將訂用帳戶設定為 Subscription07,而第五個命令會選取該訂用帳戶。
最後一個命令會在目前訂用帳戶中為名為 lpqd0zbr8y 的伺服器建立內容。
參數
-Credential
指定提供 SQL Server 驗證的認證物件,讓您存取伺服器。
類型: | PSCredential |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |
-FullyQualifiedServerName
指定 Azure SQL 資料庫 伺服器的完整功能變數名稱 (FQDN) 名稱。 例如,Server02.database.windows.net。
類型: | String |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |
-ManageUrl
指定此 Cmdlet 用來存取伺服器的 Azure SQL 資料庫 Management 入口網站的 URL。
類型: | Uri |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |
-Profile
指定此 Cmdlet 從中讀取的 Azure 設定檔。 如果您未指定設定檔,此 Cmdlet 會從本機預設配置檔讀取。
類型: | AzureSMProfile |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-ServerName
指定資料庫伺服器的名稱。
類型: | String |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | True |
接受萬用字元: | False |
-SubscriptionName
指定此 Cmdlet 用來建立連線內容的 Azure 訂用帳戶名稱。 如果您未指定此參數的值,Cmdlet 會使用目前的訂用帳戶。 執行 Select-AzureSubscription Cmdlet 來變更目前的訂用帳戶。
類型: | String |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | True |
接受萬用字元: | False |
-UseSubscription
指出此 Cmdlet 會使用 Azure 訂用帳戶來建立連線內容。
類型: | SwitchParameter |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |
輸出
Microsoft.WindowsAzure.Commands.SqlDatabase.Services.Server.IServerDataServiceContext
備註
如果您在未指定網域的情況下進行驗證,而且如果您使用 Windows PowerShell 2.0,Get-Credential Cmdlet 會傳回前面加上使用者名稱的反斜杠 (\), 例如 \user。 Windows PowerShell 3.0 不會新增反斜杠。 New-AzureSqlDatabaseServerContext Cmdlet 的 Credential 參數無法辨識此反斜杠。 若要移除它,請使用類似下列的命令:
PS C:\\\> $Credential = Get-Credential
PS C:\\\> $Credential = New-Object -TypeName 'System.Management.Automation.PSCredential' -ArgumentList $Credential.Username.Replace("\",""),$Credential.Password