Invoke-ASCmd直接在powershell中执行,但在通过SSIS脚本任务启动时不起作用

时间:2017-05-09 09:41:24

标签: sql-server powershell ssis ssas cmdlets

我在通过SSIS-Script任务处理SQL 2016表格模型时遇到问题。

在SSIS脚本任务中,我通过以下方式调用powershell脚本:

        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脚本只包含两行(加上一些用于调试的行):

Import-Module SQLASCMDLETS -Verbose 4>&1 | Out-File "folder\filename.txt"
Invoke-ASCmd -Query "plchldr_query" -Server "Servername\TABULAR"

不幸的是,当我启动SSIS包时,Invoke-ASCmd失败并显示错误消息:

  

无法加载文件或程序集   'Microsoft.AnalysisServices.PowerShell.Cmdlets'或其中一个   依赖。指针无效(HRESULT异常:0x80004003   (E_POINTER))

当我直接在powershell中启动完全相同的脚本时,一切正常。

对我而言,问题可能与不同的主机有关。当我直接在powershell中启动脚本时,主机是“Console Host”(版本4.0)。但是当我通过SSIS-Task启动脚本时,主机是“默认主机”(版本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...

所以,现在我完全陷入了困境。对我来说,两种类型的执行之间的唯一区别是执行脚本的主机。但是两个主机都有相同的模块可用。您是否可能有另外一个想法可能导致这种不同的行为?

提前致谢!

更新

我现在通过Import-Module SQLASCMDLETS检查了-Verbose来电。当我在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的\模块\ SQLASCMDLETS \ SQLASCMDLETS.psd1' 。   从路径'C:\ Program Files(x86)\ Microsoft SQL加载模块   服务器\ 130个\工具\   PowerShell的\模块\ SQLASCMDLETS \ Microsoft.AnalysisServices.PowerShell.Cmdlets.dl   L”。

我检查过这些文件存在于文件夹中。但这些消息对我而言似乎是模块的加载方式不同。这有可能吗?如果是的话,有人知道为什么吗?或者我是否误解了不同的输出?

0 个答案:

没有答案
相关问题