-
-
Save w3bward/7e42070cc714be6cafd74a22ef980324 to your computer and use it in GitHub Desktop.
An example of creating an SMO connection using the SmoRenewableToken module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module SmoRenewableToken | |
# You must run Connect-AzAccount so that an access token can be obtained from Az.Accounts | |
Connect-AzAccount | |
$SmoRenewableToken = New-SmoRenewableToken | |
# Replace these values with the values for your Azure SQL server/database | |
$Server = "myazuresqlserver.database.windows.net" | |
$Database = "MyDatabase" | |
$ConnectionInfo = [Microsoft.SqlServer.Management.Common.SqlConnectionInfo]::new($Server) | |
$ConnectionInfo.DatabaseName = $Database | |
$ConnectionInfo.AccessToken = $SmoRenewableToken | |
$ConnectionInfo.UserName = $SmoRenewableToken.UserId | |
$ServerConnection = [Microsoft.SqlServer.Management.Common.ServerConnection]::new($ConnectionInfo) | |
$ServerInstance = [Microsoft.SqlServer.Management.Smo.Server]::new($ServerConnection) | |
$DatabaseInstance = $ServerInstance.Databases | where Name -EQ $Database |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment