使用 Excel 中 VBA 宏的参数执行 .exe

Execute a .exe with arguments from VBA macro in Excel

我想编写一个 VBA 宏来通过按下 excel 中的一个按钮来执行以下 DOS 命令(已验证,有效):

powershell.exe -command "Get-ADGroupMember -identity "Sec_Tc_RWaccess" -Recursive | Get-ADUser -Property userPrincipalName, Enabled| Select userPrincipalName, Enabled | Export-csv -path C:\temp\textfile.csv"

我的想法是使用函数:

Shell (Program,WindowStyle)

但我没有设法将参数传递给 powershell.exe

欢迎使用 Whosebug!

我会运行这样的东西(未测试):

Sub test()
    Call Shell("powershell -command ""Get-ADGroupMember -identity ""Sec_Tc_RWaccess"" -Recursive | Get-ADUser -Property userPrincipalName, Enabled| Select userPrincipalName, Enabled | Export-csv -path C:\temp\textfile.csv""", vbMaximizedFocus)
End Sub

请修改您的问题,包括您尝试 运行 的确切代码。这对我们(以及其他遇到同样问题的人)有很大帮助。