【问题标题】:The 'Switch-AzSqlDatabaseFailoverGroup' command was found in the module 'Az.Sql', but the module could not be loaded在模块“Az.Sql”中找到“Switch-AzSqlDatabaseFailoverGroup”命令,但无法加载该模块
【发布时间】:2020-03-07 07:44:27
【问题描述】:

我正在尝试编写一个使用 Switch-AzSqlDatabaseFailoverGroup cmdlet 的 Powershell 脚本。该脚本将在自动化运行手册中执行,并且我已成功将Az.Sql 模块安装到自动化帐户中。但是,每当我运行这本书时,都会出现以下错误:

Switch-AzSqlDatabaseFailoverGroup : The 'Switch-AzSqlDatabaseFailoverGroup' command was found in the module 'Az.Sql', but the module could not be loaded. For more information, run 'Import-Module Az.Sql'. 

At line:42 char:5 
+ Switch-AzSqlDatabaseFailoverGroup ` 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
+ CategoryInfo : ObjectNotFound: (Switch-AzSqlDatabaseFailoverGroup:String) [], CommandNotFoundException + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

我尝试在本地机器上执行相同的脚本(安装了Az.Sql 模块)并得到同样的错误。

我是不是在某个地方漏掉了一步?

【问题讨论】:

    标签: powershell azure-sql-database azure-automation


    【解决方案1】:

    他们都在我身边工作得很好。我也可以重现你的问题,我假设你使用旧的Connect-AzureRmAccount模块登录,你需要使用Connect-AzAccount,只需使用下面的脚本。

    在自动化账户中,我使用Az.Accounts 1.6.4Az.Sql 2.0.0,你也可以和我尝试相同的版本,只需删除旧模块,导航到Browse Gallery,重新搜索并导入。

    $connectionName = "AzureRunAsConnection"
    try
    {
        # Get the connection "AzureRunAsConnection "
        $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         
    
        "Logging in to Azure..."
        Connect-AzAccount `
            -ServicePrincipal `
            -TenantId $servicePrincipalConnection.TenantId `
            -ApplicationId $servicePrincipalConnection.ApplicationId `
            -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 
    }
    catch {
        if (!$servicePrincipalConnection)
        {
            $ErrorMessage = "Connection $connectionName not found."
            throw $ErrorMessage
        } else{
            Write-Error -Message $_.Exception
            throw $_.Exception
        }
    }
    
    Switch-AzSqlDatabaseFailoverGroup -ResourceGroupName <resource-group-name > -ServerName <secondary-server-of-failover-group> -FailoverGroupName <failover-group-name>
    

    【讨论】:

    • 嗨乔伊,感谢您的回复。我目前正在使用Connect-AzureRmAccount 登录,并且正在使用与您相同版本的模块。我今天晚些时候换成Connect-AzAccount 测试一下。
    • @Cam 好吧,祝你好运。如果有效,请不要忘记将其标记为答案。
    • @Cam 你现在能拿到吗?
    • 嗨,Joy,对不起,我还没有机会测试它——我会在可以测试的时候告诉你
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-30
    相关资源
    最近更新 更多