0

I need a VBA function to return the description of AD groups.

Returning the value with Powershell would be easy:

Adgroup = "abc"
strCommand = "Powershell.exe [environment]::CurrentDirectory='C:\Windows\System32\WindowsPowerShell\v1.0'; start-job -ScriptBlock{Get-ADGroup -identity " & Adgroup & " -Properties Description | select Description | ft -HideTableHeaders} | wait-job | receive-job"
  
Set WshShell = CreateObject("WScript.Shell")
Set WshShellExec = WshShell.Exec(strCommand)
strOutput = WshShellExec.StdOut.ReadAll

Debug.Print strOutput

This code returns the correct output, however it has the downside of popping up the PS window.
I found a solution that can hide the PS window, however when I use it, the Antivirus software blocks the script. Since I do not want to mess with it, I need a different solution.

What would be a good non Powershell approach for this?

Divin3
  • 538
  • 5
  • 12
  • 27
  • You cannot just bypass the antivirus software with code. You would need to disable it manually first. – braX Feb 04 '22 at 08:13
  • @braX I used PS to return values previously into VBA with different scripts. I don't want to disable my AV software. What I need, is a different solution that is not PS. I could return `Get-ADGroup -identity " & Adgroup & " -Properties Description | select Description | ft -HideTableHeaders'`, but as I said, it's not an ideal solution. I need a different solution. This is what I'm asking in my question. – Divin3 Feb 04 '22 at 08:20
  • You may want to include that in your question then. It's always best to show people what you have tried already. – braX Feb 04 '22 at 08:24
  • @braX done. I hope now it's clear what I need – Divin3 Feb 04 '22 at 08:49
  • 2
    This Powershell approach is doomed. You can access the AD directly in VBA, the main keyword to search for is "ADSI" (Active Directory Service Interface). Random example https://stackoverflow.com/a/21113591/18771 – Tomalak Feb 04 '22 at 09:03

1 Answers1

0

Thank you Divin3 and Tomalak for your valuable discussions. Posting your discussions as answer to help other community members.

Access the AD directly in VBA. You can use ADSI (Active Directory Service Interface) for the same.

Reference: http://exceldevelopmentplatform.blogspot.com/2017/10/activedirectory-with-vba-part-4-adsi.html, https://stackoverflow.com/questions/21110232/getting-ad-details-based-on-username/21113591#:~:text=LDAP%20URIs%20require,some%20time%20ago.

Madhuraj Vadde
  • 1,099
  • 1
  • 5
  • 13