Skip to content

Instantly share code, notes, and snippets.

@Geofferey
Created May 25, 2026 15:18
Show Gist options
  • Select an option

  • Save Geofferey/2d71e2904aa855c9b663142d77224baf to your computer and use it in GitHub Desktop.

Select an option

Save Geofferey/2d71e2904aa855c9b663142d77224baf to your computer and use it in GitHub Desktop.
function Set-Attribute {
param (
[string]$Attribute,
[string]$Value
)
$searcher = New-Object System.DirectoryServices.DirectorySearcher
$searcher.Filter = "(name=$env:ComputerName)"
$result = $searcher.FindOne()
if (-not $result) {
throw "Computer object not found: $env:ComputerName"
}
$entry = $result.GetDirectoryEntry()
$entry.Put($Attribute, $Value)
$entry.CommitChanges()
Write-Host "Set $Attribute to '$Value' on $env:ComputerName"
}
Set-Attribute -Attribute "description" -Value "Test write from computer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment