Using a PowerShell script, how do I reformat the output from "Get-ADComputer -Filter * -Properties Created | FT Name,Created" and then write to reformated output to the computer description in AD.
the current output looks like this below
Name Created
---- -------
LAPTOP12 30/06/2011 10:22:52 AM
LAPTOP03 18/01/2016 3:47:06 PM
LAPTOP01 12/07/2011 11:04:29 AM
LAPTOP11 30/10/2015 8:27:00 AM
PC06 11/07/2011 2:03:17 PM
The format I am looking to create is
computername Provisioned ddMMyyyy
Then write this revised output of "Provisioned ddMMyyy" to the computer description in AD
CodePudding user response:
Get-ADComputer -Filter * -Properties Created | foreach-object { Set-ADComputer $_ -Description "Provisioned $($_.Created.ToString("ddMMyy"))" }
No need for
ft Name,Created
here becauseft
is for a human-readable outputUse the
|
(pipe) character to send the results ofGet-ADComputer
to the next commandUse
foreach-object
on the piped output to iterate through each item from theGet-ADComputer
outputUse Set-ADComputer with the
-Description
parameter to update the AD descriptionUse the .ToString method to reformat the
$_.Created
value to your desired format