Creating a Hire Date for AD users

I have a random Date Generator, but I am now trying to add this date to the desctiption of each user on the domain. As of now the only other thing in the Description is their age which is just a number.

$StartDate = Get-Date -Date 2015-01-01
$EndDate = Get-Date -Date 2022-11-11

$RangeInDays = 0..(($EndDate - $StartDate).Days)
$DaysToAdd = Get-Random -InputObjects $RangeInDays
$RandDate = $Startdate.AddDays($DaysToAdd)

Get-ADUser -Prop Description | ForEach {
    $desc = $._description + $RandDate Set-ADUser $_.sAMAccountName -Description $desc

This question and your previous question are both a bit odd. If these questions are for college assignments or homework questions, the first port of call should be your tutor.

There are several problems with the code snippet you’ve posted but you’re not far from a working solution.
Reading the error messages, correcting your syntax errors (typos), and reading the help file for Get-ADUser should point you in the right direction.

You’ll also probably want a space between the age and the date in the description :slight_smile:

1 Like