Usuário com melhor resposta
Habilitar Usuários desativados VBScript

Pergunta
-
Prezados, Boa Noite,
Gostaria de uma ajuda de vocês para agilizar meu trabalho aqui, não encontrei em canto algum essa solução, resolvi apelar aqui.
Eu tenho um servidor AD com uma árvore e várias OU's, nessas OU's tem vários usuários que estão desativados, porém, eu preciso ativar vários deles também, eu tenho em um TXT uma relação com o nome, sobrenome e usuário separados com ":" das pessoas que precisam ser ativadas, a parte da leitura do txt com split no usuário e afins tá beleza, só não sei como ler o usuário e ativar o mesmo na OU, fico grato desde já.
OBS.: Ressaltando que eu já sei como ativar usuários pelo vbs, o que eu quero realmente tentar fazer, é ativar os usuários que estão dentro do arquivo .txt- Editado Sadraque Carneiro domingo, 2 de junho de 2013 03:39
Respostas
-
Boa tarde Sadraque,
teste esse script do link : http://community.spiceworks.com/scripts/show/1692-enable-user-accounts-from-text-file
'#============================================================================== '#============================================================================== '# SCRIPT.........: EnableAccounts.vbs '# AUTHOR.........: Stuart Barrett '# VERSION........: 1.0 '# CREATED........: 20/11/2012 '# LICENSE........: Freeware '# REQUIREMENTS...: '# '# DESCRIPTION....: Enables all user accounts as specified in text file, '# saves results to log file '# '# NOTES..........: Text file should be in format: '# '# username1 '# username2 '# etc. '# '# CUSTOMIZE......: '#============================================================================== '# REVISED BY.....: '# EMAIL..........: '# REVISION DATE..: '# REVISION NOTES.: '#============================================================================== '#============================================================================== strFile = "c:\users.txt" strLogFile = "c:\enabledusers.log" Const ForReading = 1 Const ForAppending = 8 Const ADS_UF_ACCOUNTDISABLE = &H02 intCount = 0 intEnabledCount = 0 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strFile, ForReading) Set objLogFile = objFSO.OpenTextFile(strLogFile, ForAppending, True) On Error Resume Next Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") Set objConnection = CreateObject("ADODB.Connection") objConnection.Open "Provider=ADsDSOObject;" Set objCommand = CreateObject("ADODB.Command") objCommand.ActiveConnection = objConnection Set objCommand.ActiveConnection = objConnection strBase = "<LDAP://" & strDNSDomain & ">" objCommand.Properties("Page Size") = 1000 objCommand.Properties("Timeout") = 30 objCommand.Properties("Cache Results") = False booLogging = MsgBox("This script will attempt to Enabled all user accounts as specified in the text file '" & _ strFile & "' " & vbCrLf & vbCrLf & "Would you like to append the results to the log file located at '" & _ strLogFile & "'? ", vbYesNo+vbQuestion, "Enable Accounts") If booLogging = vbYes Then booLogging = True strLogMsg = "The log file can be located at: '" & strLogFile & "'" Else booLogging = False End If While not objFile.AtEndOfStream strUser = objFile.Readline strFilter = "(sAMAccountName=" & strUser & ")" strAttributes = "distinguishedName" strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" objCommand.CommandText = strQuery Set objRecordset = objCommand.Execute Do Until objRecordset.EOF strUserDN = objRecordset.Fields("distinguishedName").Value objRecordset.MoveNext Loop objRecordset.Close Set objUser = GetObject("LDAP://" & strUserDN) intUACFlag = objUser.Get("UserAccountControl") If (intUACFlag AND ADS_UF_ACCOUNTDISABLE) <> 0 Then objUser.Put "userAccountControl", 512 objUser.SetInfo Set objUser = Nothing If booLogging = True Then objLogFile.WriteLine Now() & vbTab & strUser & vbTab & "Enabled Account" intCount = intCount + 1 Else intEnabledCount = intEnabledCount + 1 strMsg = " * " & strUser & vbCrLf & strMsg If booLogging = True Then objLogFile.WriteLine Now() & vbTab & strUser & vbTab & "Already Enabled" End If WEnd If intEnabledCount <> 0 Then WScript.Echo "Enabled " & intCount & " user accounts. " & strLogMsg & vbCrLf & vbCrLf & _ "The following accounts were already enabled: " & vbCrLf & strMsg Else WScript.Echo "Enabled all " & intCount & " user accounts. " & strLogMsg End If
att, Aparecido Deveza
- Sugerido como Resposta Fábio JrModerator quarta-feira, 5 de junho de 2013 00:03
- Marcado como Resposta Fábio JrModerator quinta-feira, 6 de junho de 2013 01:39