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 (180 points)

2 Answers

by (308k points)
0 votes

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 ", "")
by (180 points)
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"

by (308k points)
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.

by (180 points)
0 votes

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

I have a report that displays the adaxes logs for a specific scheduled task initator. One of my report-specific columns runs the following script: $logRecord = $Context.ReportItem. ... to have some sort visual when an error is thrown in the execution log.

asked 1 day ago by emeisner (180 points)
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 (590 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" ... But $req contains only Test-Group--User that user is member of but it is an array

asked Oct 31, 2024 by Vish539 (500 points)
0 votes
1 answer