Script to pull out last logon date

Hello,
I have a list of user that I would like to pull out last logon date from AD.
This is the script I am using at the moment but it produces blanks and I don't know what the blanks mean.
Import-Module ActiveDirectory
#This script requires PowerShell AD Module
Import-csv "c:\scripts\samaccountname.csv" |
foreach-object {get-aduser $_.samaccountname -Properties lastlogondate} |
select name,Lastlogondate |
Export-csv c:\scripts\LastLogon.csv -NoTypeInformation
Please can you help?
Kind Regards, PenDraKon

If you want an accurate lastLogon date, you have to check across domain controllers.
Here's an advanced function I created a while ago for this.
Function Get-LastLogon {
<#
.SYNOPSIS
Returns LastLogon information
.DESCRIPTION
Queries the LastLogin information for a user across domain controllers and returns the highest (latest) value
.EXAMPLE
Get-LastLogon User
.EXAMPLE
Get-LastLogon -Identity User
.EXAMPLE
Get-ADUser User | Get-LastLogon
.EXAMPLE
Get-LastLogon User1, User2
.PARAMETER users
List of users - pipeline can be used
#>
[CmdletBinding()]
param
[Parameter(Position= 0,
Mandatory=$True,
ValueFromPipeline=$True,
HelpMessage='What user would you like to find the last logon for?')]
$identity
Begin {}
Process {
Foreach ($account in $identity) {
$dateStamp = $null
$domainController =$null
Get-ADDomainController -Filter * | Foreach {
$dc = $_.HostName
$lastLogon = (Get-ADUser $account -Properties LastLogon -server $dc | Select-Object Name,@{n='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}}).Lastlogon
If ($dateStamp -le $lastlogon)
$dateStamp = $lastlogon
$domainController = $dc
} # End of ForEach
$properties = @{
Name=$account;
LastLogon=$dateStamp;
DomainController=$domainController}
New-Object -TypeName PSObject -Prop $properties
} # End of ForEach
} # End of Process
End {}
} # End of Function
You can then run...
Import-CSV ".\samaccountname.csv" | % {Get-LastLogon $_.samaccountname}
or...
Import-CSV ".\samaccountname.csv" | % {Get-LastLogon $_.samaccountname} | Export-CSV ".\report.csv" -noType

Similar Messages

  • Search for User by last logon date no longer works after upgrading to SPS18

    We used to be able to Search by last logon date under User Administration as a quick way to find out who logged on for a particular date.  It worked well, but only for a single date range.  We were on EP 6.0 SPS13 at the time.  Since we have upgraded to SPS18, it no longer works.  All we get back now is no user found no matter what date we enter. 
    Has anyone else experienced this problem?  I've been searching and haven't found anything.  I wanted to try and get more information before I create an OSS message.
    Thank you,
    Kathy

    it's since SP16, to be correct: http://help.sap.com/saphelp_nw04/helpdata/en/43/bc6b9202454dece10000000a422035/frameset.htm
    kr, achim

  • DB USER Last Logon Date

    Hi All,
    How to find a Database USER last logon date on 10g? by script.
    Thanks,

    You need to enable auditing to view history in audit files. In v$session you can see only connected sessions.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1830073957439
    http://www.dba-oracle.com/art_builder_sec_audit.htm

  • Last Logon date and Logon time not updating in table USR02

    Hi,
    Please help us on this. After customer successfully logged in the webshop, we are checking the table USR02 in CRM system and the Logon date and Logon time is not updated. Because of this, the customer will be locked after certain number of days. When we check it in ECC system, customer's last logon date and time is updated. Can you tell us what could be causing this? Any advise what we need to check? Thanks in advance!
    Regards,
    Mike

    Hi
    1. Please check if the USAPPLREF table in ECC has the correct mapping done between the LOGON User and the Sold-to party (Customer)
    2. Please check the validity of those user in SU01 user data.
    3. Please check the USERS data from the USERADMIN Link (if it is configured in your scenario through XCM settings for USERS)
    Hope this will help.
    Regards

  • Is there a system table or V$ view that will show a user's last logon date?

    Is there a system table or V$ view that will show a user's last logon date?
    I'm using Oracle 9.2.0.7

    sqlplus
    SQL*Plus: Release 11.2.0.1.0 Production on Tue Aug 31 12:44:42 2010
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    Enter user-name: / as sysdba
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> desc user$
    Name                            Null?    Type
    USER#                            NOT NULL NUMBER
    NAME                            NOT NULL VARCHAR2(30)
    TYPE#                            NOT NULL NUMBER
    PASSWORD                             VARCHAR2(30)
    DATATS#                       NOT NULL NUMBER
    TEMPTS#                       NOT NULL NUMBER
    CTIME                            NOT NULL DATE
    PTIME                                  DATE
    EXPTIME                             DATE
    LTIME                                  DATE
    RESOURCE$                       NOT NULL NUMBER
    AUDIT$                              VARCHAR2(38)
    DEFROLE                       NOT NULL NUMBER
    DEFGRP#                             NUMBER
    DEFGRP_SEQ#                             NUMBER
    ASTATUS                       NOT NULL NUMBER
    LCOUNT                        NOT NULL NUMBER
    DEFSCHCLASS                             VARCHAR2(30)
    EXT_USERNAME                             VARCHAR2(4000)
    SPARE1                              NUMBER
    SPARE2                              NUMBER
    SPARE3                              NUMBER
    SPARE4                              VARCHAR2(1000)
    SPARE5                              VARCHAR2(1000)
    SPARE6                              DATE

  • BAPI_USER_GET_DETAIL - Last Logon Date not available

    From R3 I want to check the last logon Date (USR02-TRDAT) of a user in an outside system such as EBP or BW.  BAPI_USER_GET_DETAIL seemed like a good choice but TRDAT is not passed to the BAPI. Last Logon Time is (LTIME) but not Last logon date (TRDAT). How can this be easily done.
    Thanks,
    -don.

    the problem with this is that it makes a call for each user. If you have 100k users it becomes a very inefficient process.
    If you build something in the backend to collect the details a useble format....1) it is custom, and 2) you need to deply in each backend and 3) maintain it in each backend.
    not a good solution.
    If anyone has better idea please shout. Again....this RFC call does the job.....but it is like empting a pool full of water with a  teaspoon, does the job but very inefficiently.
    DenisO

  • Last Logon Date for Deleted Users

    Hi,
    How can I checked to see last logon date for a deleted user-SAP ECC 6.0?
    -Wes

    > ... chekcing USR02 the TRDAT field has been reset.
    In lower releases you could easily have made a big mistake doing that.
    In all releases the security audit log (SM20) is the correct tool for this, but you cannot retro-fit it.
    If the SM20 log is not activated for logon events, then there are several other ways of reconstructing parts of the information but they are all incomplete and a big effort.
    Cheers,
    Julius

  • PowerShell Active Directory: Get last logon date of a deleted user

    So, my first post in this noble community. I've been lurking here and I've been getting some good information. Hopefully, you guys can help me in this concern which may be simple to some but I couldn't seem to get around it.
    Is it possible to get the last logon date of a DELETED user in Active Directory?
    I can get the available properties of deleted users using the following:
    Get-ADObject -Filter {samaccountname -eq <account_name> -and ObjectClass -eq "user"} -IncludeDeletedObjects -Properties *
    But the last logon date is not one of the properties available from Get-ADObject. Get-ADUser has the last logon property, but it does not have data on deleted users. Is there anyway this can be achieved? Perhaps convert an ADObject to an ADUser?
    Any information would be much appreciated. Thank you.

    Thanks everyone for your response. It looks like jrv is leading me to the right path, but I'm still having issues. I'm trying to get the lastlogon time by querying all the DCs in our domain, but every query returns a null lastlogon time for all the deleted
    users I tried:
    $DomainControllers = ((Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ }).Name
    foreach ($DC in $DomainControllers)
        $dn=(Get-ADObject -Filter {samaccountname -eq <user_account>} -includedeletedobjects -server $DC).DistinguishedName
        $user=[adsi]"LDAP://$dn"
        $user.LastLogon
    It always returns null. Morever, simply executing [adsi]"LDAP://$dn" from each DC gives the following error:
    format-default : The following exception occurred while retrieving member
    "distinguishedName": "There is no such object on the server.
        + CategoryInfo          : NotSpecified: (:) [format-default], ExtendedType
       SystemException
        + FullyQualifiedErrorId : CatchFromBaseGetMember,Microsoft.PowerShell.Comm
       ands.FormatDefaultCommand
    It's a bit surprising to me though, since $user=[adsi]"LDAP://$dn" does return a value for $user (instead of null whenever an error is encountered) of type System.DirectoryServices.DirectoryEntry but it has no members.
    Anyone know what I'm missing?

  • Last logon date

    Hi,
    I am working on EP 7.0 SPS 13.
    We have LDAP & UME as data source.
    Is there any way to get last logon date for all users?
    UME method for getting last logon details is deprecated.
    What is alternative way?
    I need to get list of all users who have not logged on to portal for last 30 days.
    Is there any way to achieve this?
    Regards,
    Apurva

    Hi Michael,
    Thanks for the link.
    Our requirement is that if user is not active for say 30 days his userid should be locked and after say 60 days it should be deleted.
    In order to determine inactive users we need information about logon details for user ids. Portal Activity Report - Details of users who logged on does not consider reporting period and hence is of no use.
    Is there any operation in this web service which can provide us this information?
    Regards,
    Apurva

  • Query users, access level and last logon date

    <p>Hello,</p><p> </p><p>Does anybody know how to query Essbase to look up users accesslevel and last logon date?</p><p> </p><p> </p><p>Rey Fiesta</p>

    It can be done using the API. Access level is a little complicated because it can be by individual or group they belong to and it of course is different by application/database

  • How to find out last update date for business partner's marketing attribute

    How to find out last update date for business partner's marketing attribute??
    Im freshie for SAP Application and im assigned to find out last update date for marketing attribute changed
    which table is involved??
    Yours kindness will be appreciated
    thanks

    You can take a look at table AUSP as well as CRMD_AUSP_HIST.
    The "changed by" and "changed at" are logged on attribute level, not on attribute value level. When you change one specific value, the system does a "re-insert" of all existing values of this attribute.
    Take a look at the SAP notes 938426 and 966670  these may assit you in resolving the issue.
    Regards,
    William Laverde

  • Script needed to query last logon for users within an AD security group

    Hi all,
    I'm looking for a vbscript that will query a specific AD security group, and export the following information into an Excel document:
    1. Full name of the user.
    2. A timestamp of the last logon for each user.
    Any help would be great.

    At the moment I'm using a batch script to attempt to query a few different security groups. Below is a line from the script:
    dsquery group -samid <group name> | dsquery * -filter "&(objectClass=person)(ObjectCategory=user)" -attr cn lastLogonTimestamp
    There a two issues with the command.
    1. The results aren't being pulled from the security group specified.
    2. The timestamp is in an unreadable format. I've understand this needs to be converted?
    The Powershell option looks handy, but sadly the clients environment is Server 2003 based with no Powershell option.

  • Dates -- Pulling the last year data!, which should'nt be the case.

    Need some basic SQL Help ..
    Iam supposed to pull the data based on a date column(end_time) -- Yesterday 3PM untill Today's 3PM.
    Iam getting last year's data too in additon to Current Data.
    Where am i comparing wrong??
    SELECT a.*
    FROM table a
    WHERE TO_CHAR (a.action_end_time, 'MM/DD/YYYY HH24:MM:SS') >=
    TO_CHAR (SYSDATE - 1, 'MM/DD/YYYY')
    || ' 15:00:00'
    AND TO_CHAR (a.action_end_time, 'MM/DD/YYYY HH24:MM:SS') <=
    TO_CHAR (SYSDATE, 'MM/DD/YYYY')
    || ' 15:00:00'
    ORDER BY a.end_time;

    Date math, 1 = 1 day 1 / 24 = 1 hour, trunc with no date format gives midnight
    Try this.
    select a.* from table a where
      a.action_end_time between trunc(sysdate) + (15 * 1 / 24)
                            and trunc(sysdate - 1) + (15 * 1 / 24) In your example you are comparing strings, not dates.

  • Shell script to pull out value of tablespace used %age...

    Oracle 11gR1 RHEL5
    Hi all,
    I'm sure there is something out there, but I was wondering if anyone knew an easy way to create a script the will take a value from a sql script and then if is a certain value or greater, then it will email me. So basically I'm trying to figure out how I can get a shell script to read sql output (tablespace free space) and grab let's say any tablespace that is more than 80% full, and then send me an email with the tablespace name. I have some references but just can't seem to figrue out the reading the value part. I'm still kinda new to the shell scripting world...but eager to learn.
    Thanks.

    Here is what I have so far. I am getting a permission denied error
    #!/bin/bash
    FILE=freespace.log
    DATECMD=/bin/date
    FREESPACELOG="${DIR}/freespace.`date '+%Y%m%d-%H:%M:%S'`.log"
    DIR=/home/oracle/scripts/bin/free_space/logs
    cd /home/oracle/scripts/bin/free_space/
    sqlplus -S "/ as sysdba" << EOF > $FREESPACELOG
    set lines 300 pages 400
    select tbs.tablespace_name,
    tot.bytes/1024 total,
    tot.bytes/1024-sum(nvl(fre.bytes,0))/1024 used,
    sum(nvl(fre.bytes,0))/1024 free,
    (1-sum(nvl(fre.bytes,0))/tot.bytes)*100 pct,
    decode(
    greatest((1-sum(nvl(fre.bytes,0))/tot.bytes)*100, 80),
    80, '', '*'
    ) pct_warn
    from dba_free_space fre,
    (select tablespace_name, sum(bytes) bytes
    from dba_data_files
    group by tablespace_name) tot,
    dba_tablespaces tbs
    where tot.tablespace_name = tbs.tablespace_name
    and fre.tablespace_name(+) = tbs.tablespace_name
    group by tbs.tablespace_name, tot.bytes/1024, tot.bytes
    order by 5, 1;
    exit &exit_status
    EOF
    *./test.sh: line 7: /freespace.20090331-12:46:53.log: Permission denied*
    Edited by: JrOraDBA on Mar 31, 2009 12:48 PM

  • Can OC/RDC monitor a user's last logon date?

    Can OC/RDC monitor if a user has not logged in for 30 days, or 60 days, and send them an email, or lock their account?

    Hi,
    If you are looking for the option to email the users - > you have to have your own custom code .
    enable the audit trail to DB level. sys.aud$ will store all the login details - you can schedule a job to run every day and see if users didn't login for > 90 days send out email.
    If you are only looking for the way to lock the account then its gonna be easy - create a new database profile with the settings you need.
    How does one enforce strict password controls?
    By default Oracle's security is not extremely good. For example, Oracle will allow users to choose single character passwords and passwords that match their names and userids. Also, passwords don't ever expire. This means that one can hack an account for years without ever locking the user.
    From Oracle 8 one can manage passwords through profiles. Some of the things that one can restrict:
    * FAILED_LOGIN_ATTEMPTS - failed login attempts before the account is locked
    * PASSWORD_LIFE_TIME - limits the number of days the same password can be used for authentication
    * PASSWORD_REUSE_TIME - number of days before a password can be reused
    * PASSWORD_REUSE_MAX - number of password changes required before the current password can be reused
    * PASSWORD_LOCK_TIME - number of days an account will be locked after maximum failed login attempts
    * PASSWORD_GRACE_TIME - number of days after the grace period begins during which a warning is issued and login is allowed
    * PASSWORD_VERIFY_FUNCTION - password complexity verification script
    Look at this simple example:
    read http://www.orafaq.com/wiki/Oracle_database_Security_FAQ for more details.
    HTH

Maybe you are looking for

  • Void and return help

    whats the difference of using void and using the return? i used last time the void and return, but the outputs of the two are the same

  • Unable to do Down Payment request F-47 against Stock transfer order

    Dear All, Business create STO. in the STO they entered few conditions for expenses. now Business is trying to do down payment request ( F-47) against Stock transfer order ( STO ). but they are getting error message "no invoice expected for item 00001

  • MacBook Pro compatible with 3G iPod (five-button)????

    Any chance that my 3G iPod (the one with four buttons and the wheel) will be compatible with my new MacBook Pro? I'd have to at least buy a Firewire 400 to Firewire 800 converter. But there's no point in buying one if the iPod won't otherwise be comp

  • Last approver of purchase requisition linked to workflow

    Hi Guys, Im writting a report to display retrospectively the usernames of the last approvers of a company's purchase requisitions for auditing purposes. After searching the forum I found a way to do this: 1) use SAP_WAPI_WORKITEMS_TO_OBJECT to retrie

  • String convertions

    Hi, Is there any routine or function module to have all special country characters translated into standard characters, let's say to A-Z a-z and 0-9 ? I mean all special characters codes because I get short dump that convertion fails. It is special c