小编Luc*_*caS的帖子

从VBA调用Powershell脚本(带参数)

我想从Excel VBA调用Powershell-Script并传递1个参数.如果没有VBA,脚本可以完美运行并完成它应该做的事情.一旦Call工作,我想添加1个参数,但首先成功调用...

但我无法在Excel VBA中调用它.第一次看到我的Powershell-Script:

#param([string]$server)
$server = "chvmes01"

$BasicPath = Split-Path $script:MyInvocation.MyCommand.Path

write-host $BasicPath

Invoke-Command -FilePath $BasicPath\IISReport.ps1 -ComputerName $server

Read-Host "Return drücken..."
Run Code Online (Sandbox Code Playgroud)

在VBA中,我创建了此代码:

strCommand = "Powershell.exe -ExecutionPolicy ByPass -NoExit -File """ & BasicPath & """, 1"
Set WsShell = CreateObject("WScript.Shell")
WsShell.Run (strCommand)
Run Code Online (Sandbox Code Playgroud)

strCommand看起来像这样:

Powershell.exe -ExecutionPolicy Unrestricted -NoExit -File"E:\ Temp\Registry\EXCEL_ALLE\Version_AllFromExcel_Aktuell\IISReport\InvokeCommand.ps1",1

像这样我得到以下错误: 在此输入图像描述

我不知道我可以改变什么,我阅读了很多论坛帖子并改变了不同的东西,但没有任何效果!

我尝试使用strCommand而不是像这样:

strCommand = "Powershell.exe -ExecutionPolicy ByPass -NoExit -File " & BasicPath & ", 1"
Run Code Online (Sandbox Code Playgroud)

我试过了

-ExecutionPolicy Unrestricted AND -ExecutionPolicy ByPass 
Run Code Online (Sandbox Code Playgroud)

我有没有尝试过

-NoExit
Run Code Online (Sandbox Code Playgroud)

我也试过了

Shell (strCommand)
Run Code Online (Sandbox Code Playgroud)

正如我所提到的,Scripts在没有VBA的情况下完美运行!有人可以帮忙吗?

excel powershell vba

5
推荐指数
1
解决办法
2027
查看次数

标签 统计

excel ×1

powershell ×1

vba ×1