﻿# encoding: utf-8
# api: multitool
# category: bulk
# title: -Filter user search
# description: queries AD users by filter, generate list as table/csv
# version: 0.1
# vars:
#    {
#       name: filter,
#       type: select,
#       select: '(office -like "*Oxford*")|(l -like "*France*")|(division -eq 32156)|(description -like "*finance*")|(company -like "*Google") -and (department -like "Engineering*")'.
#       description: "-Filter attributes or properties. Use -like and * for fuzzy search, or -eq for exact matches. Multiple attributes can be combined with -and / -or, or wrapped in parens."
#    }
#    { name: display, type: select, select: "Format-Table|ConvertTo-Html|Out-GridView|Format-List|Export-CSV", description: "How to output result list." }
#    { name: export_fn, type: file, description: "Filename for Export-cSV" }
#    {
#       name: props,
#       type: select,
#       select: "SAMAccountName Name EmailAddress|SAMAccountName Name EmailAddress Manager EmployeeType Company Description L Enabled AccountExpirationDate",
#       description: AD fields to list
#    }
# icon: user
# type: inline
# depends: psm:ad
# priority: experimental
#
# Shortcut for Get-ADUSer -Filter
# A few sample filters in combobox prepared.
# Outputs either list, table, or saves to CSV file.
#

Param(
   $filter = (Read-Host "filter"),
   $display = (Read-Host "display"),
   $export_fn = (Read-Host "export_fn"),
   $props = (Read-Host "props")
)


#-- find
$results = Get-ADUser -Filter $filter -Prop * | Select ($props -split "\W+")


#-- output
Out-DisplayDispatch $result $display $export_fn 

