I can´t seem to get this script to work, it should add text if there are anything written in the description.
It somehow always overwrite whatever is there.
Any suggestions how i can fix this?
Thanks in advance \ Thomas
Import-Module activedirectory
Define the path to the file containing AD computer names
$computersToDisable = Import-Csv (Get-ChildItem “C:\temp\checked*.csv”)
Get the current date and time
$currentDateTime = Get-Date -Format “yyyy-MM-dd HH:mm:ss”
Loop through each computer name
foreach ($computer in $computersToDisable) {
# Get the current description of the computer
$currentDescription = (Get-ADComputer -Identity $computerName).Description
# Concatenate the new text with date and time to the current description
$newDescription = "$currentDescription`nDisabled on $currentDateTime"
# Set the new description for the computer
Set-ADComputer -Identity $computerName -Description $newDescription
}