Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise Design Integration Forum List Inactive Users for a period of time
    • Sign In

    • State Not Answered
    • Replies 2 replies
    • Subscribers 61 subscribers
    • Views 685 views
    • Users 0 members are here

    List Inactive Users for a period of time

    frank henderson
    Offline frank henderson over 4 years ago

    Is there a way to list by ID all Inactive Users for a period of time?  We want to validate that if they are inactive for a certain period that they are disabled.  I looked at get-PWuserByLastLogin and I'm not entirely sure of the results that I'm getting.  It appears to also give me newly created accounts that someone has not logged into.  What I ultimately would like is if the account was create over such a period or has not logged in over a period to disable and/or delete the account.

    Thanks,

    Frank

    • Sign in to reply
    • Cancel
    Parents
    • Kevin van Haaren
      0 Offline Kevin van Haaren Fri, Sep 13 2019 4:05 PM

      Accounts created but never logged into have null for their last login date. (Also if your ProjectWise is old enough you may have accounts where the create date is null. The create date wasn't added until 2007-2008, our accounts created before then have no create date).

      It looks like Get-PWUserByLastLogin converts null last login dates to 1/1/1979 1:00:00 AM (I'm in central time, not sure that matters)

      So you'll want to drop any accounts with create dates later than the period you specified for LastLogin. powershell's get-date command and the ability to do date math is a big help here.

      # find users last logged in 2 years ago
      $DaysAgo = 365*2
      
      $old_users = Get-PWUserByLastLogin -DaysAgo $DaysAgo
      # remove users created after $DaysAgo
      # use -$DaysAgo to subtract days from today
      $old_users = $old_users | where CreationDate -lt (get-date).AddDays(-$DaysAgo)
      
      # Display users
      $old_users | select UserID,CreationDate,LastLogin | Sort CreationDate | Format-Table
      

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Fri, Sep 13 2019 4:12 PM in reply to Kevin van Haaren

      Oh I forgot you wanted disabled users, change line 7 to:

      $old_users = $old_users | where IsDisabled -eq $true | where CreationDate -lt (get-date).AddDays(-$DaysAgo)

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Reply
    • Kevin van Haaren
      0 Offline Kevin van Haaren Fri, Sep 13 2019 4:12 PM in reply to Kevin van Haaren

      Oh I forgot you wanted disabled users, change line 7 to:

      $old_users = $old_users | where IsDisabled -eq $true | where CreationDate -lt (get-date).AddDays(-$DaysAgo)

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Children
    No Data

    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies