简体   繁体   中英

Get-ADUser CSV file disabled true and false filter

The script below works as is, I need to add the enabled -eq $true piece so I can audit the user list to see if they are also enabled (not just disabled). I have tried various ways and the scripted error out. Can anyone help?

$userID = Import-Csv "c:\users.csv"

foreach ($user in $userID) {
    $employeeID = $user.employeeID
    Get-ADUser -Filter {employeeID -eq $employeeID -and Enabled -eq $false} -Properties displayName,employeeID,mail,intelOwnerID,title,"msDS-UserPasswordExpiryTimeComputed","lastLogon" |
        select "Displayname", "Enabled",
            @{n="PasswordExpiryDate";e={[DateTime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}},
            @{n='LastLogon';e={[DateTime]::FromFileTime($_.lastLogon)}},
            SamAccountName, employeeID, mail, intelOwnerID, title |
        Export-Csv -Append "c:\temp\usersacct.csv"

To get both enabled and disabled users that are listed in your .csv you just need to stop filtering on Enabled -eq $false . Just change this line:

Get-ADUser -Filter {employeeID -eq $employeeID -and Enabled -eq $false} -Properties displayName,employeeID,mail,intelOwnerID,title,"msDS-UserPasswordExpiryTimeComputed","lastLogon" |

to

 Get-ADUser -Filter {employeeID -eq $employeeID} -Properties displayName,employeeID,mail,intelOwnerID,title,"msDS-UserPasswordExpiryTimeComputed","lastLogon" |

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM