Reputation: 3
I want to write a VBA macro to execute the following DOS command (verified, works) by pressing a button in excel:
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"
My idea was to use the function:
Shell (Program,WindowStyle)
but I don't manage to pass the arguments to powershell.exe
Upvotes: 0
Views: 1507
Reputation: 3678
Welcome to StackOverflow!
I would run something like this (untested):
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
Please amend your question by including the exact code you are trying to run. That helps us (and other people who have the same problem) a lot.
Upvotes: 1