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.

Sunday 4 June 2017

Exporting AD users to CSV file using PowerShell command

Or, PowerShell command to export AD users in to a CSV file
Or, Get AD users report with all fields or selected fields with the help of PowerShell

Descriptions:  In this article, we are going to try some useful PowerShell commands to export AD users reports. You have choice to select many properties values, less properties values or all properties value as per your need.

Steps:

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

AD user’s reports with some most commonly used fields
Get-ADUser -Filter '*' -Properties * | Select -Property EmailAddress,GivenName,Surname,DisplayName,Title,Department,Office,OfficePhone,MobilePhone,Fax,StreetAddress,City,State,PostalCode,Country | Export-CSV "D:\temp\ADusers.csv" -NoTypeInformation -Encoding UTF8

AD Users report with less fields
Get-ADUser -Filter '*' -Properties * | select -Property SamAccountName,DisplayName,EmailAddress | Export-CSV "D:\temp\ADusers2.csv" -NoTypeInformation -Encoding UTF8

AD users reports with all available fields
Get-ADUser -Filter '*' -Properties * | Export-CSV "D:\temp\ADusersAllFlds.csv" -NoTypeInformation -Encoding UTF8


The reference screenshot is given below to see how the commands should look like on PowerShell.







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