0 votes

I am modifying the 'Inactive Computers' report so we can see a calculation of the days since the computer was active. I added a script column, and have this script. It doesn't seem to be getting the last logon date though as it returns 0. If I put a real date ($starttime = '5/6/19'), it does the calculation as expected. I also tried enclosing the %lastLogonTimeStamp% in quotes as I usually end up doing in powershell scripts but that didn't help.

# Assign a column value to $Context.Value
$starttime = %lastLogonTimestamp%
$endtime = (get-date)
$timespan = NEW-TIMESPAN -Start $starttime -End $endtime
$Context.Value = $timespan.days

I am trying to use Adaxes to make my team more efficient so thanks for your help on my recent tickets.

by (430 points)

1 Answer

0 votes
by (14.1k points)
selected by
Best answer

Hello!

In scripts used to generate reports or report custom columns, value references (e.g. %lastLogonTimeStamp%) resolve into values of corresponding properties of the user who initiated the report generation. To get values of report objects, first you need to get the object using the $Context.GetADObject method and then get the property value using the $object.Get method.
To add the number of days the computer is inactive for to a report custom column, use the below script:

# Get computer object
$object = $Context.GetADObject()

# Get computer last logon time
try
{
    $lastLogonTime = [DateTime]::FromFileTime([Int64]::Parse($object.Get("lastLogonTimestamp")))
}
catch 
{
    $lastLogonTime = $NULL
}

# Set column value
if ($lastLogonTime)
{
    $currentDate = Get-Date
    $timespan = NEW-TIMESPAN -Start $lastLogonTime -End $currentDate
    $Context.Value = $timespan.days
}
0

Thanks for this, and the explanation.

Related questions

0 votes
1 answer

Hi Can you lead us to what we are doing wrong with this report? `$CID ="{ed8afa99-e34d-4531-b69a-0bd0785f4d3a}" $folders = gci -force '\server\Kunden'-ErrorAction ... Value generation = Template, empty. ColumnID is double checked an is the right one. Thanks

asked Mar 5, 2020 by maca (100 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 (470 points)
0 votes
2 answers

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 ... () $line = $object.Get("description") $dateTime = ?? $Context.Value = $dateTime

asked Feb 27 by emeisner (100 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 (490 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)
3,547 questions
3,238 answers
8,232 comments
547,809 users