如何使用 powershell 为用户获取 Azure SQL 数据库密码

How to get Azure SQL DB Password for user using powershell

如果我们有使用 powershell 的用户名,我正在寻找 azure sql db 的密码。我发现 Get-AzureRmSqlDatabaseSecureConnectionPolicy cmdlet 可以获取连接字符串,但它没有密码。任何帮助将不胜感激。

谢谢, 保罗

据了解,这是不可能的。如果你可以使用PowerShell获取密码,我认为这是不安全的。 Azure 不允许这样做。

但是,您可以使用 PowerShell 重置 SQL 数据库密码。只需使用 Set-AzureRmSqlServer.

PS C:\>$ServerPassword = "newpassword"
PS C:\> $SecureString = ConvertTo-SecureString $ServerPassword -AsPlainText -Force
PS C:\> Set-AzureRmSqlServer -ResourceGroupName "ResourceGroup01" -ServerName "Server01" -SqlAdministratorPassword $secureString

当您创建 SQL Azure 数据库时,您需要提供管理员用户的名称及其密码。然后,您可以使用管理员用户 运行 涉及 SQL Azure 数据库的 PowerShell 脚本,如下所示:

# The data center and resource name for your resources
$resourcegroupname = "myResourceGroup"
$location = "WestEurope"
# The logical server name: Use a random value or replace with your own value (do not capitalize)
$servername = "server-$(Get-Random)"
# Set an admin login and password for your database
# The login information for the server
$adminlogin = "ServerAdmin"
$password = "ChangeYourAdminPassword1"
# The ip address range that you want to allow to access your server - change as appropriate
$startip = "0.0.0.0"
$endip = "0.0.0.0"
# The database name
$databasename = "mySampleDatabase"

要使用 PowerShell 创建 SQL 数据库用户,请阅读 this 文章。