Need to get sessions disconnected 10 days ago RRS feed

  • Question

  • Hi Techies, 

    I have a requirement where I need to fetch machines which got disconnected (CITRIX) 10 days ago. I am able to fetch all the disconnected sessions with SessionStateChangeTime. Something like this:

    MachineName     SessionStateChangeTime

    ABCDI051          9/4/2018 8:51:02 PM
    ABCDJ010          10/31/2018 2:37:07 PM
    ABCDJ011          10/29/2018 7:56:03 PM
    ABCDJ015          10/29/2018 4:01:49 PM
    ABCDJ016          10/31/2018 1:01:42 PM

    I need to fetch machines that were disconnected longer than 10 days back from today (31st Oct 2018). 

    I tried to do this:

    $10DaysBack=(Get-date).addDays(-10).ToString('MM/dd/yyyy hh:mm:ss tt')

    Get-BrokerDesktop -SessionState Disconnected -MaxRecordCount 6000 | where ('$_.SessionStateChangeTime' -le '$10DaysBack') | Select HostedMachineName,SessionStateChangeTime

    This isnt working and gives me no output (as if there are no machines that were disconnected longer than 10 days back). 

    Any help will be appreciated. 



    Thanks, Arun.

    • Moved by Bill_Stewart Wednesday, January 2, 2019 3:19 PM This is not "scripts on demand"
    Wednesday, October 31, 2018 7:32 AM

All replies

  • If you place single quotes around a variable it will not be a variable.  Remove the quotes.

    You cannot compare a string date to a date object.  Do not convert the date to a string.

    where ('$_.SessionStateChangeTime' -le [datetime]::Today.AddDays(-10)}


    Wednesday, October 31, 2018 8:07 AM