Attached is a fairly simple script that contains two functions. One function is a Read-InpuGUI function that I found online and the other is my Check-ADUserExist advanced function.
The script works fine for one user, but when I run the following command to call on the Read-InputGUI function to display the multi line input box to enter multiple users, and then click OK, the script will NOT produce any results - period! If I enter only one user in the multi line GUI, it will produce output just fine.
It only has issues with multiple users.
If I output the data contained in the $UserList variable to a text file to hold all the user names and then use Get-Content to grab that data, then all the users will get processed. I don’t want to have to do it this way though, since I think producing text files like this is kind of sloppy when I know there is a better way of doing it.
Command to use the input GUI:
Check-ADUserExist -ADUserName “userlist”
To check if my $UserList variable was holding multiple users, I simply output the data to the screen and all the users were displayed with no issue.
The problem looks to be that the Active Directory cmdlet may an an issue processing multiple users in this fashion using an input GUI, but that is just speculation.
Here is where it appears the issue is:
ElseIf ($ADUserName -eq "UserList")
{
$UserList = Read-InputGUI "Please Enter User Names Here:" "User List" "Input user names here and hit the Enter button for each user name entry"
Foreach ($ADDomain in $ADDomains)
{
Foreach ($ADUser in $UserList)
{
$ADUserQuery = (Get-ADUser -Filter {sAMAccountName -eq $ADUser} -Server $ADDomain).sAMAccountName
If ($ADUserQuery -eq $ADUser)
{
$OutHostNewLine
Write-Output "$ADUser exist in $ADDomain"
$OutHostNewLine
}
I would greatly appreciate an explanation why this cannot get results for multiple users and\or some help to resolve this.
Thanks everyone
-Ron