Write to Computer Object Description using PowerShell

email me

I created this to write dynamic information to the Computer Description field in Active Directory. I have included the remote and local methods.

Once this runs, the computer object description field is updated with something like this:

SOME WORDS HERE * 11/14/2016 6:24 PM * HP EliteBook 840 G2

Screenshot

Code

Import-Module ActiveDirectory

# REMOTE COMPUTER
# $ComputerName = 'RemoteComputerName'

# OR
# LOCAL COMPUTER
$ComputerName = (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name

$a = Get-Date
$b = $a.ToShortDateString()
$c = $a.ToShortTimeString()
$d = Get-WmiObject -computername $ComputerName Win32_Computersystem | Select -Expand model

if ($d -eq $null) {$d = '0000'}
#$e = $d -replace '\D+(\d+)\D+','$1'
$Description = "SOME WORDS HERE * $b $c * $d"

Set-ADComputer $ComputerName -description $Description

 

 

Notes

Something interesting you can do, is tie the Return Bitlocker Info script and this PowerShell script together. That increases functionality by allowing you to query info, for machines that are missing the Bitlocker passwords in AD, you can perform the import automatically, and the final piece, you can update the computer object description field with dynamic information.

I only had to add two small parts to bind the two scripts.

#1 – Add the following towards the bottom, but in the loop of the Return Bitlocker Info
PowerShell.Exe -File C:\_AD_Scripts\SetDescription.ps1 %PC%

 

#2 – At the top of the PowerShell script, allow a parameter to be accepted. Note in #1, you’ll be passing %PC%, which is the computer name. The following accepts the %PC% and then assigns it to $ComputerName

param ([string]$w)
$ComputerName = $W