Substitute for GetDate()-function

Currently, LOGINventory5 MMC-Application does not support the GetDate()-function in quiries like LOGINventory 4. If you want to get all assets with a scandate 30 days ago you can now use the Windows PowerShell. You just have to execute following script:

ScandateBefore30Days.ps1:

 
# Read all LOGINventory CmdLets from Registry and add them to the current session
cd HKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns
Get-ChildItem | where {$_.Name -like "*Login.Ventory.*"} | select Name | foreach {add-pssnapin $_.Name.SubString($_.Name.LastIndexOf('\')+1)}
 
# Create LOGINventory Drive change location
$d = new-psdrive -scope global -name LI -PSProvider LOGINventory -root ""
 
cd LI:\Assets
 
# perhaps you have to set the correct culture information for the Convert.ToDateTime-function of .NET
$CULTURE = New-Object System.Globalization.CultureInfo("de-DE")
function isBefore([int]$days, [string]$date)
{
   $scandate = [Convert]::ToDateTime($date, $CULTURE)
   [DateTime]::Compare([DateTime]::Now.AddDays($days).Date, $scandate.Date) -eq 1
}
 
get-LiResults | Where {isBefore -30 $_.scandatetime}

Now you can execute the job:

powershell.exe [location]\ScandateBefore30Days.ps1

2 Responses to “Substitute for GetDate()-function”

  1. Olaf H. said:

    Jul 13, 10 at 15:58

    Dear StefanS,

    will the “GetDate” function work in the query editor in a later release of Loginventory v5? I find it a pity that it currently is not available as my queries rely heavily on it in Loginventory v4.

    Regards,
    Olaf

  2. MarcoM said:

    Jul 15, 10 at 13:58

    Olaf,

    As some of our customers have requested this functionality to be available again in LOGINventory5, we have decided to reintegrate it. Of course we will do this as soon as possible but, we have to change some things behind the scenes to get it to work.


Leave a Reply