0

I need to know how to get the result in VBA Excel from Active Directory using shell, cmd, dsquery and dsget filtering by email in this way:

---> dsquery user -name m * | dsget user -email

If I write the above commands in a cmd (it doesn't need admin for the query) it returns what I ask for, now if I send it from VBA in Excel with the Shell command like this:

---> R = Shell ("cmd dsquery user -name m * | dsget user -email", vbNormalNoFocus)

a cmd opens but it does nothing else and the most curious thing is that I use those same commands in the cmd opened from VBA Excel then appears the following:

---> 'dsquery' is not recognized as an internal or external command, operable program or batch file

What am I doing wrong? Thanks very much!

John K. N.
  • 2,055
  • 1
  • 17
  • 28
  • VBA running an external executable to query AD? You really should revise your approach to this. – Massimo Apr 02 '20 at 16:43
  • Hint: https://www.google.com/search?q=vba+query+active+directory – Massimo Apr 02 '20 at 16:54
  • I have tried using powershell to do it with the powershell's parameters but when I try the code Excel closes. :o ... I'll continue researching – ttlecaster Apr 03 '20 at 17:52
  • Even if you want to do it from VBA, there are *libraries* for this. Calling an external program and parsing its output is like emailing a picture by printing it, scanning it and then attaching the scan. – Massimo Apr 03 '20 at 19:01
  • Thanks for your comments.!!! – ttlecaster Apr 05 '20 at 15:11
  • Anyway the problem is when I run a R=Shell("cmd.exe someExeFile",1) from Excel's VBA. The cmd opens but doesn't run someExeFile and when I try to run some .exe file in that oppened cmd I receive an error like: is not recognized as an internal or external command, operable program or batch file. – ttlecaster Apr 05 '20 at 15:26

1 Answers1

1

dsquery is part of an optional feature on Windows workstation. There are also much better ways of doing this than using dsquery.

Greg Askew
  • 35,880
  • 5
  • 54
  • 82
  • And there are much, ***much*** better approaches than have a VBA macro run an external executable... – Massimo Apr 02 '20 at 16:42