Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetADBitlockerRecoveryKey #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions ConfigMgrWebService/ConfigMgrWebService.asmx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,64 @@ public bool RemoveADComputer(string secret, string samAccountName)
return returnValue;
}

[WebMethod(Description = "Get the Bitlocker Recovery Key from AD")]
public string GetADBitlockerRecoveryKey(string secret, string bitlockerID)
{
MethodBase method = MethodBase.GetCurrentMethod();
MethodBegin(method);

//' Variable for Bitlocker Recovery Key
string bdeRecoveryKey = string.Empty;

//' Validate secret key
if (secret == secretKey)
{
//' Set empty value for search result
SearchResult searchResult = null;
DirectoryEntry directoryObject = null;

//' Get default naming context of current domain
string defaultNamingContext = GetADDefaultNamingContext();
string currentDomain = String.Format("LDAP://{0}", defaultNamingContext);

//' Construct directory entry for directory searcher
DirectoryEntry domain = new DirectoryEntry(currentDomain);
DirectorySearcher directorySearcher = new DirectorySearcher(domain);
directorySearcher.Filter = String.Format("(&(objectClass=msFVE-RecoveryInformation)(Name=*{0}*))", bitlockerID);
directorySearcher.PropertiesToLoad.Add("msFVE-RecoveryPassword");

//' Invoke directory searcher
try
{
searchResult = directorySearcher.FindOne();
if (searchResult != null)
{
//' Get computer object from search result
directoryObject = searchResult.GetDirectoryEntry();

if (directoryObject != null)
{
bdeRecoveryKey = (string)directoryObject.Properties["msFVE-RecoveryPassword"].Value;

// Dispose directory object
directoryObject.Dispose();
}
}
}
catch (Exception ex)
{
WriteEventLog(String.Format("An error occured when attempting to locate Active Directory object. Error message: {0}", ex.Message), EventLogEntryType.Error);
}

//' Dispose objects
directorySearcher.Dispose();
domain.Dispose();
}

MethodEnd(method);
return bdeRecoveryKey;
}

[WebMethod(Description = "Write event to web service log")]
public bool NewCWEventLogEntry(string secret, string value)
{
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The list below shows an overview of the available methods:
- SetADComputerDescription
- SetADOrganizationalUnitForComputer
- RemoveADComputerFromGroup
- GetADBitlockerRecoveryKey

## Supported Configurations
This web service has been built to support the following versions of System Center Configuration Manager:
Expand Down