簡體   English   中英

使用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

歡迎來到StackOverflow!

我將運行以下內容 (未經測試):

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

請通過添加您要運行的確切代碼來修改您的問題。 這對我們(以及其他有相同問題的人)有很大幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM