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 (60 points)
edited by

2 Answers

0 votes
by (272k 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 (60 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 (470 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

Trying to generate a custom report and getting an error when trying to add the resulting values back into the report columns - The part of code causing the issue is this - ... any way to run the $Context.Items.Add method to add multiple column values at once?

asked Sep 22, 2022 by sirslimjim (480 points)
0 votes
1 answer

Hi I'm trying to product a report to show the users with either E3, F3 or F5 licenses. If I add the Adaxes "Microsoft 365 Licenses" attribute directly to the report then ... from the user and show a nice "Microsoft E3" etc value. Is this possible? Thanks

asked Sep 27, 2021 by chappers77 (2.0k points)
3,351 questions
3,052 answers
7,791 comments
545,091 users