好的,我有这个脚本,它应该很简单:
# Load the Microsoft.AnalysisServices assembly from the NuGet package
$amoPath = (Join-Path (Join-Path $env:USERPROFILE ".nuget\packages\microsoft.analysisservices.tabular") "13.0.2150.3\lib\Microsoft.AnalysisServices.Core.dll")
Add-Type -Path $amoPath
$amoPath = (Join-Path (Join-Path $env:USERPROFILE ".nuget\packages\microsoft.analysisservices.tabular") "13.0.2150.3\lib\Microsoft.AnalysisServices.Tabular.dll")
Add-Type -Path $amoPath
# Connect to the AAS instance
$connectionString = "Provider=MSOLAP;DataSource=asazure://eastus.asazure.windows.net/myservernamehere;User ID=BlahBlah;Password=SuperSecretPassword;Persist Security Info=True;Impersonation Level=Impersonate;"
$server = New-Object Microsoft.AnalysisServices.Tabular.Server
$server.Connect($connectionString)
# Delete all databases in the server
foreach ($database in $server.Databases) {
Write-Host "Deleting database: $($database.Name)"
$database.Drop()
}
# Disconnect from the server
$server.Disconnect()
当然不是:
使用“1”个参数调用“Connect”时发生异常:“连接 字符串无效。” $server.Connect($connectionString) 类别信息:未指定:(:) [],MethodInitationException FullQualifiedErrorId:ConnectionException
有趣的是我可以在 C# 中使用相同的连接字符串做同样的事情,没有任何问题......
using (Server server = new Server())
{
server.Connect(serverConnectionString);
// Collect databases to drop in a separate list
List<Database> databasesToDrop = new List<Database>();
foreach (Database element in server.Databases)
{
databasesToDrop.Add(element);
}
databasesToDrop.AsParallel().ForAll(element =>
{
element.Drop();
});
}
我不知道问题是什么,连接字符串出了什么问题?
我尝试过使用不同的身份验证方法,确实有同样的问题,在 C# 中有效,在 powershell 中不起作用...
使用“1”个参数调用“Connect”时出现异常:“连接字符串无效。” $server.Connect($connectionString) CategoryInfo : NotSpecified: (:) [], MethodInitationException FullQualifiedErrorId : ConnectionException
上述错误是由于连接字符串不正确造成的,请检查凭据是否正确。
连接到 SQL Server Analysis Service。可以使用分析管理对象访问 SQL Server Analysis Service。使用AMO。尝试使用以下代码加载程序集并创建和初始化 SQL Server Analysis Service 的实例:
[Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.Tabular");
$SSASServer = New-Object Microsoft.AnalysisServices.Server
$SSASServer = New-Object Microsoft.AnalysisServices.Tabular.Server;
另请参阅以下 SO 答案来连接 Azure SQL 分析服务: 如何在 PowerShell 中使用 AAD 应用程序注册连接到 Azure Analysis Service 服务器 如何使用Powershell列出Azure Analysis Services下的数据库/模型?