如何使用Powershell列出Azure Analysis Services下的数据库/模型?

问题描述 投票:0回答:1

我有一项任务需要自动化。该任务涉及使用 Powershell 脚本获取 Azure Analysis Services 模型中存在的数据库/模型列表

我编写了以下Powershell脚本

$serverName = "ServerName"
$ResourceGroupName = "ResourceGroupName"

$server = Get-AzAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $serverName
 
$ServerName = $server.ServerFullName

当前使用 Get-AzAnalysisServicesServer 不会返回其下的模型/数据库,并且我没有找到任何其他可以帮助我列出数据库的命令。

在做了一些研究后,我发现了一篇建议使用 Microsoft.AnalysisServices 程序集的文章。

# Load the Microsoft.AnalysisServices assembly
[Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")

# Connect to the Azure Analysis Services server
$MyServer = New-Object Microsoft.AnalysisServices.Server

$MyServer.Connect($ServerName)

# Check if the server connection is successful
if ($MyServer.Connected) {
    Write-Output "Connected to Azure Analysis Services server: $ServerName"

    # Get the list of databases from the server
    $Databases = $MyServer.Databases

    # Check if there are databases present
    if ($Databases.Count -gt 0) {
        Write-Output "List of databases:"
        foreach ($Database in $Databases) {
            Write-Output $Database.Name
        }
    } else {
        Write-Output "No databases found on the server."
    }
} else {
    Write-Output "Failed to connect to Azure Analysis Services server: $ServerName"
}

# Close the connection to the server
$MyServer.Disconnect()
Write-Output "Connection to Azure Analysis Services server closed."

使用上述脚本在

$MyServer.Connect($ServerName)
处失败,并出现以下错误:
AADSTS50011: The redirect URI 'some url' specified in the request does not match the redirect URIs configured for the application '<application_id>'. Make sure the redirect URI sent in the request matches one added to your application in the Azure portal.

有没有其他方法可以获取数据库列表,或者这根本不可能?另外,由于错误中提到的应用程序 ID 不存在于我们的 Azure 订阅中,我该如何解决重定向 URI 问题。

azure azure-powershell azure-analysis-services
1个回答
0
投票

如何使用 PowerShell 列出 Azure Analysis Services 下的数据库/模型:-

您正在加载的类型不适合列出 Azure 分析服务器上的模型。使用

New-Object Microsoft.AnalysisServices.Tabular.Server
而不是
New-Object Microsoft.AnalysisServices.Server

还要检查所提供的输入是否正确,没有任何冲突。

我尝试了下面的脚本来实现您的要求并按预期工作。

[Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.Tabular")
$serverName = "asazure://eastus.asazure.windows.net/myserverj"
Connect-AzAccount
$context = Set-AzContext -SubscriptionId "xxx"
$server = New-Object Microsoft.AnalysisServices.Tabular.Server
$server.Connect($serverName)
$server.Databases

输出:

enter image description here

$server.Databases | select Name

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.