I need some help but am not sure if this is the right place for it, Please advise me if i should do this in somewhere else.

My issue is this, i am a Helpdesk specialist who is trying to write a VBScript to get he BitLocker password recovery for a specific computer. Actually i did and it's working perfectly with a lot of help of Microsoft Technet website.

the problem is i need to modify this script to search not for the computer name and save its info as require, but to search for the Password ID of the Bitlocker from the AD computer object attributes. Please note that i am very new to scripting so my question could be stupid and i don't know.

Why modify !? Because when a computer stops working while asking for the Bitlocker password recover info i can't get the computer name as there is no access to the OS.

I would really appreciate if anyone could help me in this as it would make my life so easy.

I have access to the required OU in the AD ( M-Computers ), so this want be an issue ( I guess ).

My script is below:


Dim MAC_NAME
MAC_NAME = InputBox("Please Enter the Computer Name","Computer Name")
While(MAC_NAME="" Or Len(MAC_NAME)<>15 Or UCase(Left(MAC_NAME,3))<>"MAC")
    If IsEmpty(MAC_NAME) Then
        WScript.Echo "Script will now exit, Please Contact Musanada IT Helpdesk - Alaa Mahmoud."
        WScript.Quit
    End if
    WScript.Echo "Invalid Computer Name"
    MAC_NAME = InputBox("Please Enter the Computer Name","Computer Name")
Wend
winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& MAC_NAME &""
'Set objNetwork = CreateObject("WScript.Network")
'MAC_NAME = objNetwork.ComputerName
Set fso = CreateObject("scripting.filesystemobject")
Set objtextfile = fso.OpenTextFile("d:\BitLocker-Pass.txt", 2, True)
const strFilePath = ("D:\BitLocker-Pass.txt")
' --------------------------------------------------------------------------------
' Get path to Active Directory computer object associated with the computer name
' --------------------------------------------------------------------------------
Function GetStrPathToComputer(MAC_NAME) 
'     Uses the global catalog to find the computer in the forest
'     Search also includes deleted computers in the tombstone
    Set objRootLDAP = GetObject("LDAP://rootDSE")
    namingContext = objRootLDAP.Get("defaultNamingContext") ' e.g. string dc=Services,dc=Musanada,dc=net    
    strBase = "<GC://" & namingContext & ">"

        Set objConnection = CreateObject("ADODB.Connection") 
    Set objCommand = CreateObject("ADODB.Command") 
    objConnection.Provider = "ADsDSOOBject" 
    objConnection.Open "Active Directory Provider" 
    Set objCommand.ActiveConnection = objConnection 

    strFilter = "(&(objectCategory=Computer)(cn=" & MAC_NAME & "))"
    strQuery = strBase & ";" & strFilter  & ";distinguishedName;subtree" 

    objCommand.CommandText = strQuery 
    objCommand.Properties("Page Size") = 100 
    objCommand.Properties("Timeout") = 50
    objCommand.Properties("Cache Results") = False 

    '     Enumerate all objects found. 
    Set objRecordSet = objCommand.Execute 
    If objRecordSet.EOF Then
      objtextfile.WriteLine "The computer name '" & MAC_NAME & "' cannot be found."
      WScript.Quit 1
    End If

    '     Found object matching name
    Do Until objRecordSet.EOF 
      dnFound = objRecordSet.Fields("distinguishedName")
      GetStrPathToComputer = "LDAP://" & dnFound
      objRecordSet.MoveNext 
    Loop 

    '     Clean up. 
    Set objConnection = Nothing 
    Set objCommand = Nothing 
    Set objRecordSet = Nothing 

End Function
' --------------------------------------------------------------------------------
' Securely access the Active Directory computer object using Kerberos
' --------------------------------------------------------------------------------
Set objDSO = GetObject("LDAP:")
strPathToComputer = GetStrPathToComputer(MAC_NAME)
objtextfile.WriteLine "Accessing object: " + strPathToComputer
Const ADS_SECURE_AUTHENTICATION = 1
Const ADS_USE_SEALING = 64 '0x40
Const ADS_USE_SIGNING = 128 '0x80
' --------------------------------------------------------------------------------
' Get all BitLocker recovery information from the Active Directory computer object
' --------------------------------------------------------------------------------
' Get all the recovery information child objects of the computer object
Set objFveInfos = objDSO.OpenDSObject(strPathToComputer, vbNullString, vbNullString, ADS_SECURE_AUTHENTICATION + ADS_USE_SEALING + ADS_USE_SIGNING)
objFveInfos.Filter = Array("msFVE-RecoveryInformation")
' Iterate through each recovery information object and saves any existing key packages
nCount = 1
strFilePathCurrent = " " & strFilePath
For Each objFveInfo in objFveInfos
   strName = objFveInfo.Get("Name")

   strRecoveryPassword = objFveInfo.Get("msFVE-RecoveryPassword")

   objtextfile.WriteLine ""
   objtextfile.WriteLine ""
   objtextfile.WriteLine "Recovery Object Name:"
   objtextfile.WriteLine Mid(strName,27,8)
   objtextfile.WriteLine ""
   objtextfile.WriteLine "Recovery Password:" 
   objtextfile.WriteLine strRecoveryPassword
   objtextfile.WriteLine ""

Next
'    Validate file path
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(strFilePathCurrent)) Then
    objtextfile.WriteLine "The file " & strFilePathCurrent & " already exists. Please use a different path."
    WScript.Quit -1
End If

   objtextfile.WriteLine ""
   objtextfile.WriteLine ""
   objtextfile.WriteLine "Related key package successfully saved to " + strFilePathCurrent
WScript.Echo ("Operation Completed Successfuly, Please check Outpot file")
WScript.Quit

link|improve this question
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.