Last active
April 2, 2024 18:15
-
-
Save danton721/30c7131646e8e42b8a3877aff6149bca to your computer and use it in GitHub Desktop.
Get AD country for given UPN using AZ CLI in Excel using VBA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Usage as Excel function: =getCountryFromAD("UPN") | |
Function getCmdlineOutput(cmd As String) | |
CreateObject("WScript.Shell").Run "cmd /c """ & cmd & "|clip""", 0, True 'output>clipbrd | |
With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") 'latebound clipbrd obj | |
.GetFromClipboard 'get cmdline output from clipboard | |
getCmdlineOutput = .GetText(1) 'return clipboard contents | |
End With | |
End Function | |
Public Function getCountryFromAD(email As String) As String | |
getCountryFromAD = getCmdlineOutput("az ad user show --query " & Chr(34) & "country" & Chr(34) & " --id " & email) | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment