Microsoft.ActiveDirectory.Management.ADPropertyValueCollection

Rising Flight 3,891 Reputation points
2021-08-18T15:01:05.917+00:00

Hi All i am using the below syntax to export all my users from an OU i am not getting output at last login. i am using below syntax and at last login i am getting output as Microsoft.ActiveDirectory.Management.ADPropertyValueCollection

Get-ADUser -Filter * -SearchBase "OU=OU1,DC=contoso,DC=com" -properties * | Select-Object Name,Description, UserprincipalName,SamAccountName,LastLogin | export-csv C:\temp\output.csv -Encoding UTF8 -NoTypeInformation
Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,498 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,398 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,260 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,971 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,403 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,111 Reputation points
    2021-08-18T21:11:01.077+00:00

    No that won't work. The lastLogon property isn't in a format that is understood by PowerSell in its raw format.

    This should, though:

    Get-ADUser -Filter * -SearchBase "OU=OU1,DC=contoso,DC=com" -properties * | Select-Object Name,Description,UserprincipalName,SamAccountName,@{n='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}} | 
     export-csv C:\temp\output.csv -Encoding UTF8 -NoTypeInformation
    
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Rich Matheisen 45,111 Reputation points
    2021-08-18T19:29:00.673+00:00

    First, the property name is "lastlogOn", not "lastlogIn".
    Second, the value in that propertry is not a PowerShell DateTime object. It requires conversion (like this, assuming $_ represents the AD user object):

    $lastLogon = [datetime]::FromFileTime($_.lastLogon)
    

    Third, the lastlogon property is not replicated. It represents the last logon time on THIS domain controller. If you want the most recent logon time you'll have to query each DC and select the most recent value.
    Fourth, if you have only a single DC you can avoid the need to convert the value and use the LastLogonDate property instead. Do NOT use this property if you have more than one DC because although it's replicated, the replication interval is a random period between 9 and 14 days -- so you'd still have to look at each DC and select the most recent time.

    0 comments No comments

  2. Rising Flight 3,891 Reputation points
    2021-08-18T20:58:17.797+00:00
    Get-ADUser -Filter * -SearchBase "OU=OU1,DC=contoso,DC=com" -properties * | Select-Object Name,Description, UserprincipalName,SamAccountName,lastLogon | export-csv C:\temp\output.csv -Encoding UTF8 -NoTypeInformation
    

    i believe above syntax should work.?

    0 comments No comments

  3. Rising Flight 3,891 Reputation points
    2021-08-18T21:30:09.14+00:00

    i am getting hash error, not sure what mistake i am making


  4. Rising Flight 3,891 Reputation points
    2021-08-19T08:43:23.007+00:00

    i am getting below error

    Select-Object : A positional parameter cannot be found that accepts argument 'System.Object[]'.
    At line:1 char:126

    • ... perties * | Select-Object Name,Description,UserprincipalName,SamAccou ...
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidArgument: (:) [Select-Object], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand