在模块“ Az.Sql”中找到“ Switch-AzSqlDatabaseFailoverGroup”命令,但无法加载该模块

我正在尝试编写使用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模块)上执行相同的脚本,并且遇到相同的错误。

我在某个地方错过了一步吗?

netcrazier 回答:在模块“ Az.Sql”中找到“ Switch-AzSqlDatabaseFailoverGroup”命令,但无法加载该模块

他们俩都在我这边工作正常。我也可以重现您的问题,假设您使用旧的Connect-AzureRmAccount模块登录,则需要使用Connect-AzAccount,只需使用以下脚本即可。

enter image description here

在自动化帐户中,我使用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>
本文链接:https://www.f2er.com/3123052.html

大家都在问