I am working on a Powershell script (with a GUI) to help my colleagues easier find redundant and disabled AD accounts.
Here is a little preview...
$props = "Name, Enabled, PasswordExpired, Company,passwordNeverExpires, Office"
$propsAsArray = $props -split ',\s*'
Get-ADUser -filter * -properties $propsAsArray | where {$_.Enabled -eq $true} | where {$_.PasswordNeverExpires -eq $false}| where {$_.passwordexpired -eq $false} | Select-Object $propsAsArray | Export-csv -Path "C:\report.csv"
This all works fine and outputs a CSV report.
The snag though is how to assign all the possible combinations and permutations of AD account status to a variable and later substitute in the variable into the Get-ADUser
cmdlet (depending on which radio button the user clicks in the GUI).
I've tried all can think of but only ever get back the error Expressions are only allowed as the first element of a pipeline
.
I'm sure that $accountStatus = "where {$_.Enabled -eq $true} | where {$_.PasswordNeverExpires -eq $false}"
(or subtle variants) are not how it is done.
I'm relatively new to Powershell and am eager to get experience. Thanks, William.