0

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

1
  • 2
    What did you try? Any quotes within the Program string need to be doubled. Commented Feb 14, 2019 at 14:15

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot. these double quotes solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.