Sql server 调用ASCmd在直接在powershell中执行时有效,但在通过SSIS脚本任务启动时无效
我在通过SSIS脚本任务处理SQL 2016表格模型时遇到问题 在SSIS脚本任务中,我通过以下方式调用powershell脚本:Sql server 调用ASCmd在直接在powershell中执行时有效,但在通过SSIS脚本任务启动时无效,sql-server,powershell,ssis,ssas,cmdlets,Sql Server,Powershell,Ssis,Ssas,Cmdlets,我在通过SSIS脚本任务处理SQL 2016表格模型时遇到问题 在SSIS脚本任务中,我通过以下方式调用powershell脚本: RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create(); Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration); runspac
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
runspace.Open();
// Configure Variables
Pipeline pipeline = runspace.CreatePipeline();
string query = Dts.Variables["XMLA"].Value.ToString();
//Read in powershell script
string script = readFile(@"folder");
script = script.Replace("plchldr_query", query);
pipeline.Commands.AddScript(script);
writeFile(@"folder", script);
try
{
pipeline.Invoke();
} catch(Exception e)
{
writeFile(@"folder", e.Message);
}
此powershell脚本仅包含两行(加上一些用于调试的行):
不幸的是,当我启动SSIS包时,调用ASCmd失败,并显示错误消息:
无法加载文件或程序集
“Microsoft.AnalysisServices.PowerShell.cmdlet”或其
依赖关系。无效指针(来自HRESULT:0x80004003的异常
(E_指针)
当我直接在powershell中启动完全相同的脚本时,一切正常
对我来说,问题可能与不同的主机有关。当我直接在powershell中启动脚本时,主机是“控制台主机”(版本4.0)。但当我通过SSIS任务启动脚本时,主机是“默认主机”(版本4.0)
为了检查哪些模块可用,我执行了以下命令:
Get-Module -ListAvailable | out-file "folder\file"
我认为此列表可能有所不同,但无论我是直接在powershell中还是通过SSIS执行此命令,结果都是一样的:
ModuleType Name ExportedCommands
---------- ---- ----------------
Manifest SqlServer {Invoke-ProcessCube, New-SqlCngColumnMas...
Manifest BitsTransfer {Complete-BitsTransfer, Add-BitsFile, Re...
Manifest CimCmdlets {New-CimSessionOption, Get-CimAssociated...
Script ISE {Import-IseSnippet, Get-IseSnippet, New-...
Manifest Microsoft.PowerShell.Diagnostics {New-WinEvent, Export-Counter, Get-WinEv...
Manifest Microsoft.PowerShell.Host {Start-Transcript, Stop-Transcript}
Manifest Microsoft.PowerShell.Management {Remove-WmiObject, Remove-EventLog, Add-...
Manifest Microsoft.PowerShell.Security {Get-Credential, Get-Acl, Set-Authentico...
Manifest Microsoft.PowerShell.Utility
Manifest Microsoft.WSMan.Management {Test-WSMan, Set-WSManInstance, Get-WSMa...
Manifest PSDiagnostics {Set-LogProperties, Enable-WSManTrace, S...
Binary PSScheduledJob {Get-JobTrigger, Add-JobTrigger, Get-Sch...
Manifest TroubleshootingPack {Get-TroubleshootingPack, Invoke-Trouble...
Manifest AppvClient
Binary ThirdPartyNotice
Binary UEV {Restore-UevUserSetting, Get-UevAppxPack...
Manifest SQLASCMDLETS {Add-RoleMember, New-RestoreFolder, Invo...
Manifest SQLPS {Backup-ASDatabase, Get-SqlInstance, New...
所以,现在我完全被卡住了。对我来说,这两种执行类型之间的唯一区别是执行脚本的主机。但两台主机都有相同的可用模块。你是否知道是什么导致了这种不同的行为
提前谢谢
更新:
我现在通过-Verbose
检查了导入模块SQLASCMDLETS调用。在powershell中执行此命令时,我得到以下输出:
Importing cmdlet 'Add-RoleMember'.
Importing cmdlet 'Backup-ASDatabase'.
Importing cmdlet 'Invoke-ASCmd'.
Importing cmdlet 'Invoke-ProcessASDatabase'.
Importing cmdlet 'Invoke-ProcessCube'.
Importing cmdlet 'Invoke-ProcessDimension'.
Importing cmdlet 'Invoke-ProcessPartition'.
Importing cmdlet 'Invoke-ProcessTable'.
Importing cmdlet 'Merge-Partition'.
Importing cmdlet 'New-RestoreFolder'.
Importing cmdlet 'New-RestoreLocation'.
Importing cmdlet 'Remove-RoleMember'.
Importing cmdlet 'Restore-ASDatabase'.
使用SSIS执行的输出为:
正在从路径“C:\Program Files(x86)\Microsoft SQL”加载模块
服务器\130\Tools\PowerShell\Modules\sqlascmdles\sqlascmdles.psd1'。
正在从路径“C:\Program Files(x86)\Microsoft SQL”加载模块
服务器\130\工具\
PowerShell\Modules\SQLASCMDLETS\Microsoft.AnalysisServices.PowerShell.Cmdlets.dl
l’
我检查了文件夹中是否存在这些文件。但对我来说,这些消息似乎表明模块的加载方式有所不同。这可能吗?如果是,有人知道原因吗?还是我误解了不同的输出 您是否在与SSIS包相同的上下文中运行了导入模块SqlServer(可能附加
-ErrorAction Stop
)?我怀疑此返回的错误消息将为您提供所需的信息!!嗨,谢谢你的回复。我尝试了这个,现在抛出了一条新的错误消息。我将其添加到主帖子中,现在将尝试解决此问题。
Importing cmdlet 'Add-RoleMember'.
Importing cmdlet 'Backup-ASDatabase'.
Importing cmdlet 'Invoke-ASCmd'.
Importing cmdlet 'Invoke-ProcessASDatabase'.
Importing cmdlet 'Invoke-ProcessCube'.
Importing cmdlet 'Invoke-ProcessDimension'.
Importing cmdlet 'Invoke-ProcessPartition'.
Importing cmdlet 'Invoke-ProcessTable'.
Importing cmdlet 'Merge-Partition'.
Importing cmdlet 'New-RestoreFolder'.
Importing cmdlet 'New-RestoreLocation'.
Importing cmdlet 'Remove-RoleMember'.
Importing cmdlet 'Restore-ASDatabase'.