Wednesday 7 June 2017

PowerShell command to export AD uses created in last 7 days in to a CSV file

Or, Exporting AD users created in last 7 days to CSV file using PowerShell command
Or, Get AD users report created in last 7 days with the help of PowerShell


Descriptions:  If you are looking for exporting AD users created in last 7 days or any custom days in a CSV file/report, this article is for you my friend. In my case, I am going to export users created in last 7 days.

Steps:
Run Windows PowerShell as Administrator > run the commands mentioned below to get the CSV output/report

AD users created in last 7 days

Get-ADUser -Filter "Name -like '*'" -Properties Name, Title, Office, Created | where {$_.Created -gt $(Get-Date).AddDays("-7")} | select Name, Title, Office | Export-Csv D:\temp\ADReport.csv


Cheers, Please write me back if you have any query or feedback on this.

Tuesday 6 June 2017

Exporting inactive AD users to CSV file using PowerShell command

Or, PowerShell command to export inactive AD uses in to a CSV file
Or, Get inactive AD users report with the help of PowerShell

Descriptions:  If you are looking for exporting inactive AD users in to a CSV file/report, this article is for you my friend. In my case, I am going to export users whoever are inactive since 30 days.

Steps:
Run Windows PowerShell as Administrator > run the commands mentioned below to get the CSV output/report

Inactive AD users since 30 days

Search-ADAccount -UsersOnly -AccountInactive -TimeSpan 30 | ?{$_.enabled -eq $True} | Get-ADUser -Properties Name, EmailAddress, Department, Description, lastLogonTimestamp | Select Name, EmailAddress, Department, Description,@{n='lastLogonTimestamp';e={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} | Export-Csv D:\temp\funytest.csv


Cheers, Please write me back if you have any query or feedback on this.