Dim strFilePath strFilePath = Inputbox("Please provide a path for the CSV file","Provide Filename","*.csv") Dim rootDSE, domainObject Set rootDSE=GetObject("LDAP://RootDSE") domainContainer = rootDSE.Get("defaultNamingContext") Set domainObject = GetObject("LDAP://" & domainContainer) Set fs = CreateObject ("Scripting.FileSystemObject") Set userFile = fs.CreateTextFile (strFilePath) ExportUsers(domainObject) Set oDomain = Nothing MsgBox "Script Completed" WScript.Quit Sub ExportUsers(oObject) Dim oUser For Each oUser in oObject Select Case oUser.Class Case "user" If oUser.mail <> "" then userFile.Write "," & oUser.displayName & "," & oUser.sAMAccountName & "," & oUser.userprincipalname & "," On error Resume Next for each email in oUser.proxyAddresses userFile.Write email & "," next userFile.WriteLine "" End if Case "organizationalUnit" , "container" If UsersinOU (oUser) then ExportUsers(oUser) End if End select Next End Sub Function UsersinOU (oObject) Dim oUser UsersinOU = False for Each oUser in oObject Select Case oUser.Class Case "organizationalUnit" , "container" UsersinOU = UsersinOU(oUser) Case "user" UsersinOU = True End select Next End Function