0 votes

I am trying to create a report-specific column (DateTime - Regular Date) where I can extract the datetime from the description field of the user object using a regular expresssion.

The description field is popluated similar to "Deprovisioned on 1/20/23 8:20:20 AM by me@email.com"

$object = $Context.GetDirectoryObject() $line = $object.Get("description")

$dateTime = ??

$Context.Value = $dateTime

by (100 points)
edited by

2 Answers

0 votes
by (294k points)

Hello,

The easiest way would be to just add the Description column to the report. However, if you need a column with only the dates from the Description property and it always starts with Deprovisioned on and ends with the required date, you can use the below code. The report specific column should be of the Text type.

$object = $Context.GetDirectoryObject()
$string = $object.Get("description")

$Context.Value = $string.Replace("Deprovisioned on ", "")
0

I apologize, my initial question didn't include all the information.

The description field is popluated similar to "Deprovisioned on 1/20/23 8:20:20 AM by me@email.com"

0

Hello,

Unfortunately, there is no easy way to achieve the desired as it requires parsing strings. The best solution here is to preserve the date not only in the text Description property, but also in a custom date attribute (e.g. CustomAttributeDate1). In this case, you will only need to add the attribute column to the report.

0 votes
by (100 points)

I was able to accomplish this with the following value calculation of a regular date custom column.

$description = ""
$object = $Context.GetDirectoryObject()

try{
    $description = $object.Get("description")
}
catch [System.Runtime.InteropServices.COMException]
{}

if($description.Contains("Deprovisioned")){
    $datePattern = "(((((0[13578])|([13578])|(1[02]))[\-\/\s]?((0[1-9])|([1-9])|([1-2][0-9])|(3[01])))|((([469])|(11))[\-\/\s]?((0[1-9])|([1-9])|([1-2][0-9])|(30)))|((02|2)[\-\/\s]?((0[1-9])|([1-9])|([1-2][0-9]))))[\-\/\s]?\d{4})(\s(((0[1-9])|([1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))"
    $matches = $description | Select-String -Pattern $datePattern -AllMatches 
    $date = Get-Date $matches.Matches[0].Value
    $tzone = Get-TimeZone -Id "Central Standard Time"
    $Context.Value = $date.AddHours( - ($tzone.BaseUtcOffset.totalhours))
}

Related questions

0 votes
1 answer

Hello, I have a report of computers in multiple groups that I used to create a chart count of "Computers" in certain security memberships relating to agent software. ... a member of the group written in the script. Any assistance is appreciated. Thanks!

asked Nov 7, 2023 by Edogstraus00 (490 points)
0 votes
1 answer

I'm trying to retrive the Microsoft 365 License product name in a report as the 'Office 365 License' attribute in Adaxes shows each individual licensed product e.g. ... 365 F3"} } $productnames = $productnames -join ", " $Context.Value = $productnames

asked Jul 27, 2020 by richarddewis (260 points)
0 votes
1 answer

I have an export that will run as a monthly scheduled task that will write output to a CSV to contain employees that have been ... ([datetime]terminationDate>=$lastMonth))" $properties = $eachFieldIn $userSearcher.SetPropertiesToLoad($properties)

asked Nov 2, 2015 by sandramnc (870 points)
0 votes
1 answer

Hi support, We have security groups named like Test-Group--Users, where is different for each group. I have a powershell query which gets a list of those Test-Group--Users" ... only Test-Group-<variable>-User that user is member of but it is an array

asked Oct 31 by Vish539 (460 points)
0 votes
1 answer

I want to add a custom column in a report that displays members of a group that shows the age of the user account in days. Is that possible?

asked Oct 23 by msheppard (660 points)
3,589 questions
3,278 answers
8,303 comments
548,136 users