Given your requirements, I suggest using C# for this task. C# has a wide range of capabilities, supports Active Directory updates, and can be compiled into standalone executables without any additional dependencies. Additionally, C# has a relatively small executable size.
First, you'll need to install the C# SDK and the Active Directory Domain Services (AD DS) module if you don't have them already.
Here's a sample script that should accomplish your requirements:
using System;
using System.Collections.Generic;
using System.DirectoryServices.ActiveDirectory;
using System.Management;
using System.Runtime.InteropServices;
class Program
{
static void Main(string[] args)
{
string computerName = Environment.MachineName;
string loggedInUser = Environment.UserName;
DateTime currentDateTime = DateTime.Now;
// Gather computer information
string makeModelSerial = GetComputerMakeModelSerial(computerName);
string processorInfo = GetProcessorInfo(computerName);
uint memoryGB = GetComputerMemory(computerName);
List<string> disks = GetDisks(computerName);
// Update Active Directory attributes
UpdateExtensionAttribute(computerName, "extensionAttribute1", makeModelSerial);
UpdateExtensionAttribute(computerName, "extensionAttribute2", processorInfo);
UpdateExtensionAttribute(computerName, "extensionAttribute3", memoryGB.ToString());
UpdateExtensionAttribute(computerName, "extensionAttribute4", string.Join(", ", disks));
UpdateExtensionAttribute(computerName, "extensionAttribute5", loggedInUser);
UpdateExtensionAttribute(computerName, "extensionAttribute6", currentDateTime.ToString());
Console.WriteLine("AD updates completed successfully.");
}
static string GetComputerMakeModelSerial(string computerName)
{
// Replace this with the actual method to get the make, model, and serial of the computer
return "Dell Precision 3520 000123456";
}
static string GetProcessorInfo(string computerName)
{
// Replace this with the actual method to get the processor information of the computer
return "Intel Core i7-6820HQ";
}
static uint GetComputerMemory(string computerName)
{
// Replace this with the actual method to get the memory of the computer in GB
uint memoryGB = 16;
return memoryGB;
}
static List<string> GetDisks(string computerName)
{
// Replace this with the actual method to get the disks and their sizes of the computer
List<string> disks = new List<string> { "C: 250GB", "D: 500GB" };
return disks;
}
static void UpdateExtensionAttribute(string computerName, string attributeName, string attributeValue)
{
try
{
using (var dirEntry = new DirectoryEntry($"LDAP://{computerName}"))
{
var adpc = new ADPropertyChangeController(dirEntry);
dirEntry.Properties[attributeName].Value = attributeValue;
adpc.CommitChanges();
}
}
catch (Exception ex)
{
Console.WriteLine($"Error updating attribute '{attributeName}': {ex.Message}");
}
}
}
To compile the script into a standalone executable, follow these steps:
- Open a command prompt or PowerShell window.
- Navigate to the directory where the script file is located.
- Run the following command:
csc /target:exe /out:adUpdater.exe adUpdater.cs
This will create a file named "adUpdater.exe" in the current directory. The size of the compiled executable should be around 1 MB or less, depending on the size of the C# SDK and other installed libraries.
Note that the methods for gathering computer information (GetComputerMakeModelSerial, GetProcessorInfo, GetComputerMemory, and GetDisks) are placeholders and need to be replaced with your actual implementation.