Get current server date time from Active Roles

Hello,

Anyone please let me know how to get current server date time or how to convert current date time to specific timezone within the active roles and I wanted to set the date time to a virtual attribute. I'm unable to fix this issue. Here is the code I've using. Do let me know if you need any other info.

$currentDt = Get-Date
$currentDt = Get-Date $currentDt -Format "M/d/yyyy hh:mm:ss"

Thanks

Parents
  • The one thing I notice is that your Format probably isn't going to work.  I would do this:

    $currentDt = Get-Date $currentDt -Format "MM/dd/yyyy hh:mm:ss"

    For 'M' you have the choice of 'MM' or 'MMM' (the latter spells out the month - e.g. JUL)

    For 'd', you need to use 'dd'


  • Whoops...

    $currentDt = Get-Date -Format "MM/dd/yyyy hh:mm:ss"

  • I tried but still seeing issue.

    Below is the OnPostUnDeprovision code, I'm using to set an attribute value to match the current server date time.

    $currentDt = Get-Date
    $currentDt= $currentDt.AddHours(7)
    $currentDt = Get-Date $currentDt -Format "MM/dd/yyyy hh:mm:ss"
    Set-QADUser -Proxy $dn -ObjectAttributes @{'namm-UndoDeprovisionDate'=$currentDt}

    Below are the values after running the code.

    Current Server date time: 8/23/2022 7:08 AM

    namm-UdeoDeprovisionDate: 8/22/2022 7:08 PM 

    I wanted to update the attribute value wit Current Server date time.

    Let me know if you need any other info.

    Thanks,

    Kishore

Reply
  • I tried but still seeing issue.

    Below is the OnPostUnDeprovision code, I'm using to set an attribute value to match the current server date time.

    $currentDt = Get-Date
    $currentDt= $currentDt.AddHours(7)
    $currentDt = Get-Date $currentDt -Format "MM/dd/yyyy hh:mm:ss"
    Set-QADUser -Proxy $dn -ObjectAttributes @{'namm-UndoDeprovisionDate'=$currentDt}

    Below are the values after running the code.

    Current Server date time: 8/23/2022 7:08 AM

    namm-UdeoDeprovisionDate: 8/22/2022 7:08 PM 

    I wanted to update the attribute value wit Current Server date time.

    Let me know if you need any other info.

    Thanks,

    Kishore

Children
No Data