I have a txt file with users SamAccountName and need to parse the file to see which users are enabled and which users are disabled.
Do you have the Active Directory module available or the Quest AD Cmdlets? Depending on which Cmdlets or Classes you would like to use there are different approaches.
I have the Active Directory module.
Then you can use the Get-Content and the Get-ADUser Cmdlets to gather this information. What you can do is for each computer in the text file execute a Get-ADUser command and return only the samaccountname and the enabled properties of the returned objects.
Try the following code:
I used the code below to get the info needed. Thank you very much for the feedback.
Get-Content C:\users.txt | Get-ADUser | select SamAccountName,Enabled | Out-File C:\AcctStatus.csv
Excellent, I would however advise you to use Export-Csv rather than Out-File when you want to write to a delimited file. Try the following code:
Excellent suggestion. Many thanks for the feedback and guidance.
No problem, if there are any additional questions feel free to drop by!
Same Scenario with .csv file with the login id .Can you please help me on the same ?