代码之家  ›  专栏  ›  技术社区  ›  SherlockSpreadsheets

从命令运行时PowerShell.ps1脚本文件被删除

  •  2
  • SherlockSpreadsheets  · 技术社区  · 6 年前

    当我从执行PowerShell脚本文件时 Command Prompt Window 文件就消失了。命令窗口不显示任何错误消息,它只是在执行命令后立即转到下一行。我从备份还原文件。

    当我从执行PowerShell脚本文件时 Power Shell Window ,进程成功完成。

    当我试图使用 Execute Process Task in SSIS 如张贴在 SQL Server Central: execute+process+task MSDN Blog Article: run-powershell-scripts-in-ssis .

    什么导致文件消失?

    .ps1文件使用数据连接刷新Excel文件并保存该文件。


    电源外壳,测试命令(只有第一个失败,其他3个工作)

    PS H:\> "PowerShell.exe" "-F C:\SVN\BusinessAnalysts\ExcelTools\DatabaseSSAS_UsageStats.xlsx_ExcelRefresh.ps1"
    Unexpected token '-F C:\SVN\BusinessAnalysts\ExcelTools\DatabaseSSAS_UsageStats.xlsx_ExcelRefresh.ps1' in expression
     statement.
    At line:1 char:103
    + "PowerShell.exe" "-F C:\SVN\BusinessAnalysts\ExcelTools\DatabaseSSAS_UsageStats.xlsx_ExcelRefresh.ps1" <<<<
        + CategoryInfo          : ParserError: (-F C:\SVN\Busin...xcelRefresh.ps1:String) [], ParentContainsErrorRecordEx
       eption
        + FullyQualifiedErrorId : UnexpectedToken
    
    PS H:\> powershell -noexit C:\SVN\BusinessAnalysts\ExcelTools\DatabaseSSAS_UsageStats.xlsx_ExcelRefresh.ps1
    PS H:\> PowerShell.exe -F C:\SVN\BusinessAnalysts\ExcelTools\DatabaseSSAS_UsageStats.xlsx_ExcelRefresh.ps1
    PS H:\> PowerShell.exe -File C:\SVN\BusinessAnalysts\ExcelTools\DatabaseSSAS_UsageStats.xlsx_ExcelRefresh.ps1
    PS H:\>
    

    命令提示,测试的命令(文件分解)

    PowerShell.exe -File C:\SVN\BusinessAnalysts\ExcelTools\DatabaseSSAS_UsageStats.xlsx_ExcelRefresh.ps1
    

    PowerShell执行文件消失.png

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  2
  •   marsze    6 年前

    这太奇怪了。我可以复制它。但我不能解释为什么会这样。我的猜测是,在调用PowerShell运行脚本时,这在某种程度上是路径分析中的一个优化错误。你打电话来的时候也有同样的问题 里面 PowerShell,当这样调用它时,例如:

    . "powershell.exe" -File C:\SVN\BusinessAnalysts\ExcelTools\DatabaseSSAS_UsageStats.xlsx_ExcelRefresh.ps1
    # or
    Start-Process "powershell" -Arg "-File", "C:\SVN\BusinessAnalysts\ExcelTools\DatabaseSSAS_UsageStats.xlsx_ExcelRefresh.ps1"
    

    我可以给你一些建议,哪些替代方案应该有效:

    最简单:删除或替换点!

    powershell -File "C:\SVN\BusinessAnalysts\ExcelTools\DatabaseSSAS_UsageStats_xlsx_ExcelRefresh.ps1"
    

    或者,这些变化也应起作用:

    # Pass a command which calls the script using the call operator (&)
    # Note: The single quotes are necessary! Else you will have the same behavior
    powershell -Command "& 'C:\SVN\BusinessAnalysts\ExcelTools\DatabaseSSAS_UsageStats.xlsx_ExcelRefresh.ps1'"
    
    # A workaround to avoid the issue that's probably causing this.
    # The semicolon basically puts an empty command at the beginning.
    # This supports my theory, that this is somehow an optimization bug.
    powershell -Command ";& C:\SVN\BusinessAnalysts\ExcelTools\DatabaseSSAS_UsageStats.xlsx_ExcelRefresh.ps1"
    
    # Base64-encoded version of
    # "& C:\SVN\BusinessAnalysts\ExcelTools\DatabaseSSAS_UsageStats.xlsx_ExcelRefresh.ps1"
    powershell -EncodedCommand "JgAgAEMAOgBcAFMAVgBOAFwAQgB1AHMAaQBuAGUAcwBzAEEAbgBhAGwAeQBzAHQAcwBcAEUAeABjAGUAbABUAG8AbwBsAHMAXABEAGEAdABhAGIAYQBzAGUAUwBTAEEAUwBfAFUAcwBhAGcAZQBTAHQAYQB0AHMALgB4AGwAcwB4AF8ARQB4AGMAZQBsAFIAZQBmAHIAZQBzAGgALgBwAHMAMQA="
    

    我给微软写了一些关于这方面的反馈,但是我建议你进一步调查这一点,并可能给PowerShell团队写一个bug报告。