New-AzureSqlDatabaseServerContext
Creates a server connection context.
Note
The cmdlets referenced in this documentation are for managing legacy Azure resources that use Azure Service Manager (ASM) APIs. This legacy PowerShell module isn't recommended when creating new resources since ASM is scheduled for retirement. For more information, see Azure Service Manager retirement.
The Az PowerShell module is the recommended PowerShell module for managing Azure Resource Manager (ARM) resources with PowerShell.
Syntax
ByServerNameWithSqlAuth (Default)
New-AzureSqlDatabaseServerContext
-ServerName <String>
-Credential <PSCredential>
[-Profile <AzureSMProfile>]
[<CommonParameters>]
ByManageUrlWithSqlAuth
New-AzureSqlDatabaseServerContext
-ManageUrl <Uri>
-Credential <PSCredential>
[-ServerName <String>]
[-Profile <AzureSMProfile>]
[<CommonParameters>]
ByServerNameWithCertAuth
New-AzureSqlDatabaseServerContext
-ServerName <String>
[-UseSubscription]
[-SubscriptionName <String>]
[-Profile <AzureSMProfile>]
[<CommonParameters>]
ByFullyQualifiedServerNameWithSqlAuth
New-AzureSqlDatabaseServerContext
-FullyQualifiedServerName <String>
-Credential <PSCredential>
[-Profile <AzureSMProfile>]
[<CommonParameters>]
ByFullyQualifiedServerNameWithCertAuth
New-AzureSqlDatabaseServerContext
-FullyQualifiedServerName <String>
[-UseSubscription]
[-SubscriptionName <String>]
[-Profile <AzureSMProfile>]
[<CommonParameters>]
Description
The New-AzureSqlDatabaseServerContext cmdlet creates an Azure SQL Database server connection context. Use SQL Server authentication to create a connection context to a SQL Database server by using the specified credentials. You can specify the SQL Database server by name, by the fully qualified name, or by URL. To obtain a credential, use the Get-Credential cmdlet that prompts you to specify the user name and password.
Use the New-AzureSqlDatabaseServerContext cmdlet with certificate based authentication to create a connection context to the specified SQL Database server by using the specified Azure subscription data. You can specify SQL Database server by name or by the fully qualified name. You can specify the subscription data as a parameter or it can be retrieved from the current Azure subscription. Use the Select-AzureSubscriptionhttps://msdn.microsoft.com/library/windowsazure/jj152833.aspx cmdlet to select the current Azure subscription.
Examples
Example 1: Create a context by using SQL Server authentication
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"
This example uses the SQL Server authentication.
The first command prompts you for server administrator credentials, and stores the credentials in the $Credential variable.
The second command connects to the SQL Database server named lpqd0zbr8y by using $Credential.
The final command creates a database named Database17 on the server that is part of the context in $Context.
Example 2: Create a context by using certificate based authentication
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
This example uses the certificate based authentication.
The first two commands assign values to the $SubscriptionId and $Thumbprint variables.
The third command gets the certificate identified by the thumbprint in $Thumbprint, and stores it in $Certificate.
The fourth command sets the subscription to be Subscription07, and the fifth command selects that subscription.
The final command creates a context in the current subscription for the server named lpqd0zbr8y.
Parameters
-Credential
Specifies a credential object that provides SQL Server authentication for you to access the server.
Parameter properties
Type: | PSCredential |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
ByServerNameWithSqlAuth
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
ByManageUrlWithSqlAuth
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
ByFullyQualifiedServerNameWithSqlAuth
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-FullyQualifiedServerName
Specifies the fully qualified domain name (FQDN) name for the Azure SQL Database server. For example, Server02.database.windows.net.
Parameter properties
Type: | String |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
ByFullyQualifiedServerNameWithSqlAuth
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
ByFullyQualifiedServerNameWithCertAuth
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-ManageUrl
Specifies the URL that this cmdlet uses to access the Azure SQL DatabaseManagement Portal for the server.
Parameter properties
Type: | Uri |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
ByManageUrlWithSqlAuth
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Profile
Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile.
Parameter properties
Type: | AzureSMProfile |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-ServerName
Specifies the name of the database server.
Parameter properties
Type: | String |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
ByServerNameWithSqlAuth
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | True |
Value from remaining arguments: | False |
ByServerNameWithCertAuth
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | True |
Value from remaining arguments: | False |
-SubscriptionName
Specifies the name of the Azure subscription that this cmdlet uses to create the connection context. If you do not specify a value for this parameter, the cmdlet uses the current subscription. Run the Select-AzureSubscription cmdlet to change the current subscription.
Parameter properties
Type: | String |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
ByServerNameWithCertAuth
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | True |
Value from remaining arguments: | False |
ByFullyQualifiedServerNameWithCertAuth
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | True |
Value from remaining arguments: | False |
-UseSubscription
Indicates that this cmdlet uses Azure subscription for creating the connection context.
Parameter properties
Type: | SwitchParameter |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
ByServerNameWithCertAuth
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
ByFullyQualifiedServerNameWithCertAuth
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Outputs
Microsoft.WindowsAzure.Commands.SqlDatabase.Services.Server.IServerDataServiceContext
Notes
If you authenticate without specifying a domain, and if you use Windows PowerShell 2.0, the Get-Credential cmdlet returns a backslash (\) prepended to the username, for example, \user. Windows PowerShell 3.0 does not add the backslash. This backslash is not recognized by the Credential parameter of the New-AzureSqlDatabaseServerContext cmdlet. To remove it, use commands similar to the following:
PS C:\\\> $Credential = Get-Credential
PS C:\\\> $Credential = New-Object -TypeName 'System.Management.Automation.PSCredential' -ArgumentList $Credential.Username.Replace("\",""),$Credential.Password