Usuário com melhor resposta
Script não traz o atributo do usuario de Active Directory - AccountExpires

Pergunta
-
Pessoal, eu utilizo o script abaixo , que gera um Excel com os dados do AD.
Porem o ultimo atributo que adicionei para ser exportado não é gerado na planilha. Alguem pode me auxiliar como aproveitar esse mesmo script para obter a data de expiração da conta do usuário ???
' Script to export user information from AD to Excel
'Const cStatus = 1
Const cSAMaccountName = 2
Const cDisplayName = 3
Const cDepartment = 4
Const cOffice = 5
Const cCompany = 6
Const cOfficePhone = 7
Const cmail = 8
Const cScriptPath = 9
Const cDescription = 10
Const cManager = 11
Const cStorageQuota = 12
Const cOverQuotaLimit = 13
Const cOverHardQuotaLimit = 14
Const cPasswordLastChanged = 15
Const cwhencreated = 16
Const cLastLogin = 17
Const cEmployeeID = 18
Const cEmployeeType = 19
Const cAccountExpires = 20
Set oRootDSE = GetObject("LDAP://RootDSE")
sAnswer = UCase (InputBox ("Please select Export or Import. Type E or I", "AD Export / Import","E"))If sAnswer = "E" Then
sDomainName = oRootDSE.Get("DefaultNamingContext")
sDomainName = "LDAP://" & InputBox ("Please indicate Container: ","AD Export / Import",""& sDomainName)
If sDomainName = "LDAP://" Then WScript.Quit'Inicia Excel
Set XL = CreateObject("Excel.Application")
XL.workbooks.add
XL.Visible = True
XL.Cells.Select
XL.Selection.NumberFormat = "@"
XL.Columns(cPasswordLastChanged).Select
XL.Selection.NumberFormat = "mm/dd/yyyy"
XL.Range("A1").SelectiRow = 1
XL.Cells(iRow, cStatus) = "Conta desabilitada"
XL.Cells(iRow, cSAMAccountName) = "login"
XL.Cells(iRow, cDisplayName) = "Nome"
XL.Cells(iRow, cDepartment) = "Departmento"
XL.Cells(iRow, cOffice) = "setor"
XL.Cells(iRow, cCompany) = "Empresa"
XL.Cells(iRow, cOfficePhone) = "ramal"
XL.Cells(iRow, cmail) = "email"
XL.Cells(iRow, cScriptPath) = "LogonScript"
XL.Cells(iRow, cDescription) = "Cargo"
XL.Cells(iRow, cManager) = "Gerente"
XL.Cells(iRow, cStorageQuota) = "alerta cota"
XL.Cells(iRow, cOverQuotaLimit) = "proibe envio"
XL.Cells(iRow, cOverHardQuotaLimit) = "proibe envio e receb"
XL.Cells(iRow, cPasswordLastChanged) = "ultima alteraçao senha"
XL.Cells(iRow, cwhencreated) = "data criacao"
XL.Cells(iRow, cLastLogin) = "ultimo logon"
XL.Cells(iRow, cEmployeeID) = "matricula"
XL.Cells(iRow, cEmployeeType) = "tipo"
XL.Cells(iRow, cAccountExpires) = "STATUS"'Lê Primeiro Nível escolhido
Export sDomainName'Finaliza
XL.Selection.CurrentRegion.Columns.AutoFit
XL.Selection.CurrentRegion.Rows.AutoFit
XL.Columns("C:C").Select
XL.ActiveWindow.FreezePanes = True
XL.Range("A1").Select
MsgBox "Export complete." & vbCRLF & vbCRLF & "CRLF in address field has been replaced by *\" & vbCRLF & "Please save Excel spreadsheet"
WScript.QuitElseIf sAnswer = "I" Then
Import'IGNORAR ESSA ETAPA
Else
MsgBox "Input E or I"End If
'-----------------------------------------------------------------------------------------------------------------
Sub Export(sDomainName)Set oDomain = GetObject(sDomainName )
'oDomain.Filter = Array("user")For each obj In oDomain
If obj.class ="organizationalUnit" then
Export "LDAP://" & obj.distinguishedname
elseif obj.class = "user" thenWith obj
If .sn & .GivenName <> "" Then
iRow = IRow + 1
XL.Cells(iRow, cStatus) = .AccountDisabled
XL.Cells(iRow, cSAMAccountName) = .SAMAccountName
XL.Cells(iRow, cDisplayName) = .DisplayName
XL.Cells(iRow, cDepartment) = .department
XL.Cells(iRow, cOffice) = .physicalDeliveryOfficeName
XL.Cells(iRow, cCompany) = .company
XL.Cells(iRow, cOfficePhone) = .telephonenumber
XL.Cells(iRow, cmail) = .mail
XL.Cells(iRow, cScriptPath) = .ScriptPath
XL.Cells(iRow, cDescription) = .Description
XL.Cells(iRow, cManager) = .Manager
On Error Resume Next
XL.Cells(iRow, cStorageQuota) = .mDBStorageQuota
XL.Cells(iRow, cOverQuotaLimit) = .mDBOverQuotaLimit
XL.Cells(iRow, cOverHardQuotaLimit) = .mDBOverHardQuotaLimit
err.clear
On Error Resume Next
sPasswordLastChanged = .passwordlastchanged
If Err.Number <> 0 Then sPasswordLastChanged=""
XL.Cells(iRow, cPasswordLastChanged)= cDate(sPasswordLastChanged)
XL.Cells(iRow, cwhencreated) = .whencreated
XL.Cells(iRow, cLastLogin) = .LastLogin
XL.Cells(iRow, cEmployeeID) = .EmployeeID
XL.Cells(iRow, cEmployeeType) = .EmployeeType
XL.Cells(iRow, cAccountExpires) = .AccountExpires
On Error Goto 0
End IfEnd With
end if
Next
End Sub
'-----------------------------------------------------------------------------------------------------------------Sub Import
End Sub
'-----------------------------------------------------------------------------------------------------------------
Sub Update (oUser, sProperty, sNewValue, sText, sUpdate)
End Sub
Respostas
-
Olá, Você já considerou a tratativa abaixo?
On Error Resume Next Set objUser = GetObject _ ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com") dtmAccountExpiration = objUser.AccountExpirationDate If Err.Number = -2147467259 Or dtmAccountExpiration = "1/1/1970" Then WScript.Echo "No account expiration date specified" Else WScript.Echo "Account expiration date: " & objUser.AccountExpirationDate End If
Fonte: https://gallery.technet.microsoft.com/scriptcenter/b16d7de4-8224-4c8a-b8ad-1b38f6ef1e08
https://inframicrosoft.wordpress.com/
- Marcado como Resposta Adrian Finco quarta-feira, 21 de dezembro de 2016 13:30
Todas as Respostas
-
Olá, Você já considerou a tratativa abaixo?
On Error Resume Next Set objUser = GetObject _ ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com") dtmAccountExpiration = objUser.AccountExpirationDate If Err.Number = -2147467259 Or dtmAccountExpiration = "1/1/1970" Then WScript.Echo "No account expiration date specified" Else WScript.Echo "Account expiration date: " & objUser.AccountExpirationDate End If
Fonte: https://gallery.technet.microsoft.com/scriptcenter/b16d7de4-8224-4c8a-b8ad-1b38f6ef1e08
https://inframicrosoft.wordpress.com/
- Marcado como Resposta Adrian Finco quarta-feira, 21 de dezembro de 2016 13:30
-