Is there a way to filter out empty fields when grabbing the data from the Active Directory and then inserting it into a SQL table? When I used -Filter on Get-ADUser I don't think this is the correct syntax for doing this.
It fails saying
The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input
$ADARRAY = (Get-ADGroupMember -Identity "Domain Users" -Recursive |
Get-ADUser -Filter {-not (Mail -like "*")} -Properties Mail)
foreach($OBJECT in $ADARRAY) {
$NAME = $OBJECT.Name
$USER = $OBJECT.SamAccountName
$EMAIL = $OBJECT.Mail
$INSERT = "INSERT $TABLE VALUES ('$USER','$EMAIL', '$NAME')"
$SQL.CommandText = $INSERT
$SQL.ExecuteNonQuery()
}
$SQLCON.Close()