SAM2009
asked on
How to remove the number of days from "4/22/2019 5:00:30 AM (180 days ago)" with PowerShell?
Hi,
I need to import users info from csv. The problem is the date format in lastlogon header from the csv, like:
4/22/2019 5:00:30 AM (180 days ago)
When I will do:
$users | Select SamAccountName,Lastlogon
How can I keep just the date and not the number of days, like: 4/22/2019 5:00:30 AM?
I need to import users info from csv. The problem is the date format in lastlogon header from the csv, like:
4/22/2019 5:00:30 AM (180 days ago)
When I will do:
$users | Select SamAccountName,Lastlogon
How can I keep just the date and not the number of days, like: 4/22/2019 5:00:30 AM?
or this
[datetime]($a -split ' \(')[0]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The csv is produced by an application. That is why I have no choice to make some changes with PowerShell because the date format can’t be read.
OK; then the import with a Select-Object and a calculated property as described above is the way to go.
Hi,
This work for me
Get-ADUser -Filter * -Properties SamAccountName, Lastlogondate | Select SamAccountName, Lastlogondate | export-csv C:\Temp\test.csv
The output date looks like this 9/13/2019 8:30:41 AM
The you can make to all format you need with Excel
This work for me
Get-ADUser -Filter * -Properties SamAccountName, Lastlogondate | Select SamAccountName, Lastlogondate | export-csv C:\Temp\test.csv
The output date looks like this 9/13/2019 8:30:41 AM
The you can make to all format you need with Excel
Open in new window