Last active
February 28, 2018 09:59
-
-
Save gioxx/181130bdb9a58db9df08ea4839cc5106 to your computer and use it in GitHub Desktop.
Un VBScript che ti permette di modificare il campo attribute "personalTitle" di LDAP in maniera più rapida (vedi: https://wp.me/pdQ5q-94H)
This file contains 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
' "personalTitle" Modifier (LDAP attibute) | |
' ----------------------------------------------------------------------------------------------------------- | |
' Autore: GSolone | |
' Versione: 0.1 | |
' Utilizzo: .\personalTitleModifier.vbs | |
' .\personalTitleModifier.vbs mario.rossi | |
' ATTENZIONE: utilizzare -se possibile- direttamente sul DC | |
' Ultima modifica: 27-02-2018 | |
' ----------------------------------------------------------------------------------------------------------- | |
' Fonti utilizzate: | |
' https://social.technet.microsoft.com/Forums/scriptcenter/en-US/defcd4c8-1d6f-429c-b5d2-e8b66e857d60/reading-custom-attributes-from-ad-using-vbscript?forum=ITCG | |
' https://social.technet.microsoft.com/Forums/scriptcenter/en-US/64466490-346e-4ceb-945c-58b957b5f8de/vbscript-modify-custom-attribute-for-all-users-in-domain?forum=ITCG | |
' https://stackoverflow.com/questions/27347045/vbscript-inputbox-how-to-identify-when-the-cancel-button-is-pressed | |
' http://www.pierotofy.it/pages/guide/Guida_VBScript/Le_MsgBox/ | |
' | |
' ------------------------------------------------------------------------------------------------------------ | |
' Modifiche: | |
' - | |
set WshShell = CreateObject("WScript.Shell") | |
' Constants for the NameTranslate object. | |
Const ADS_NAME_INITTYPE_GC = 3 | |
Const ADS_NAME_TYPE_NT4 = 3 | |
Const ADS_NAME_TYPE_1779 = 1 | |
' Determine DNS name of domain from RootDSE. | |
Set objRootDSE = GetObject("LDAP://RootDSE") | |
strDNSDomain = objRootDSE.Get("defaultNamingContext") | |
' Use the NameTranslate object to find the NetBIOS domain name from the | |
' DNS domain name. | |
Set objTrans = CreateObject("NameTranslate") | |
objTrans.Init ADS_NAME_INITTYPE_GC, "" | |
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain | |
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4) | |
' Remove trailing backslash. | |
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1) | |
if WScript.Arguments.Count = 0 then | |
strName = InputBox("Enter domain username" & vbCrLf & "(ex: rossi)", "personalTitleModifier") | |
else | |
strName = Wscript.Arguments(0) | |
end if | |
' Use the Set method to specify the NT format of the user name. | |
' Trap error if user does not exist. | |
On Error Resume Next | |
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strName | |
If (Err.Number <> 0) Then | |
On Error GoTo 0 | |
'DEBUG | |
'Wscript.Echo "User " & strNTName & " does not exist" | |
MsgBox strNTName & " does not exist",vbCritical,"personalTitleModifier" | |
Wscript.Quit | |
End If | |
On Error GoTo 0 | |
' Use the Get method to retrieve the RPC 1779 Distinguished Name. | |
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779) | |
' Bind to the user object. | |
Set objUser = GetObject("LDAP://" & strUserDN) | |
' DEBUG: Display attribute of user. | |
'Wscript.Echo objUser.personalTitle | |
Dim strPersonalTitle | |
strPersonalTitle = InputBox("Current title: " & objUser.personalTitle & vbCrLf & vbCrLf & "Enter new personalTitle (clic on Cancel OR press ESC to quit)", "personalTitleModifier", objUser.personalTitle) | |
If IsEmpty(strPersonalTitle) Then | |
'cancelled | |
MsgBox "Operation has been cancelled",vbExclamation,"personalTitleModifier" | |
Else | |
'something has entered even zero-length | |
objUser.Put "personalTitle", strPersonalTitle | |
objUser.SetInfo | |
MsgBox objUser.DisplayName & " is now " & objUser.personalTitle,vbInformation,"personalTitleModifier" | |
'DEBUG | |
'Wscript.Echo objUser.personalTitle | |
End If |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment