I have a csv file which contains a list of user names with no header. I want to end up with a second csv file which contains ONLY those user names that correspond to Active Directory users who are disabled.
I was playing around with a Get-Content
and then ForEach-Object
( %
) loop to query the AD and return each SAM and the status of it's enabled property.
Get-Content users.csv | % {Get-ADUser $_ | Select-Object samaccountname,enabled}
Although what I really need to do is look at each name and move ONLY the ones tied to disabled accounts to a new csv file. Only I cant quite sort out how to accomplish this.
you're almost there:
$users = @(gc users.csv | % {Get-ADUser $_ | select samaccountname,enabled})
$users | ? { -not($_.enabled) } | export-csv -notypeinformation $somecsv
what we're doing:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.