Answered by:
Need PowerShell command to fetch "Disabled users" from my csv file

Question
-
Hi All,
I hope you will help me.
I have to fetch Disabled users from my csv file that has all users account of my AD. The output should be piped to csv file. Due to the beginner for PowerShell, I don't know this. Please help me for this issue. Thanks.
Friday, August 16, 2019 1:12 PM
Answers
-
If you use a input file with a column name SamAccountName
Import-CSV -Path "C:\Filepath\file.txt" | Get-ADUser -Identity $_.SamAccountName -Filter * -Property Enabled | Select Name, Enabled | Export-CSV -NoTypeInformation -Path "C:\Filepath\file.txt"
If you retreive all users from AD:
Get-ADUser -Filter * -Property Enabled | Select Name, Enabled | Export-CSV -NoTypeInformation -Path "C:\Filepath\file.txt"- Edited by W_Smits Friday, August 16, 2019 1:27 PM
- Proposed as answer by Stoyan ChalakovMVP Friday, August 16, 2019 2:14 PM
- Marked as answer by Hamid Sadeghpour SalehMVP Thursday, September 5, 2019 8:17 PM
Friday, August 16, 2019 1:24 PM
All replies
-
If you use a input file with a column name SamAccountName
Import-CSV -Path "C:\Filepath\file.txt" | Get-ADUser -Identity $_.SamAccountName -Filter * -Property Enabled | Select Name, Enabled | Export-CSV -NoTypeInformation -Path "C:\Filepath\file.txt"
If you retreive all users from AD:
Get-ADUser -Filter * -Property Enabled | Select Name, Enabled | Export-CSV -NoTypeInformation -Path "C:\Filepath\file.txt"- Edited by W_Smits Friday, August 16, 2019 1:27 PM
- Proposed as answer by Stoyan ChalakovMVP Friday, August 16, 2019 2:14 PM
- Marked as answer by Hamid Sadeghpour SalehMVP Thursday, September 5, 2019 8:17 PM
Friday, August 16, 2019 1:24 PM -
Friday, August 16, 2019 2:13 PM
-
Get-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and
then try running the command again.
At line:1 char:81
+ ... 29\Geek\disable.csv" | Get-ADUser -Identity $_.SamAccountName -Filter ...Thank you so much for your help.The output comes as above. But i did what you told like SamAccountName in column
And also one doubt. I asked for disabled user should be a output. But your command seems to be enabled user. Please clarify. Thanks.
Friday, August 16, 2019 2:14 PM -
Please take the time to learn basic PowerShell instead of asking others to write a script for you one line at a time.
See the post at the top of this forum for help in how to use forums.
\_(ツ)_/
Friday, August 16, 2019 3:32 PM -
Thank you. Could you please any study resource to study powershell at beginner level.Friday, August 16, 2019 3:55 PM
-
Please read the link I posted. It has resources for learning PowerShell.
\_(ツ)_/
Friday, August 16, 2019 4:06 PM -
Thanks for your timely helpFriday, August 16, 2019 5:25 PM