I am having an issue when I am reading a multiline textbox and taking users first and last name, then running a search and returning values from AD.
Here is the code:
function GetUserInfoName
{
$usersearch1 = $textbox15.Text.Split("`n")
foreach ($obj in $usersearch1)
{
$usersearchsplit = -split $obj
$trackuser0 = $usersearchsplit[0]
$trackuser1 = $usersearchsplit[1]
if ($usersearchsplit[0] -eq $null)
{ (new-object -ComObject wscript.shell).Popup("Please enter Search Criteria.", 0, "Search Criteria Error", 0) }
else
{
$usersearchresult = @()
$findusersearch1 = Get-ADUser -Filter { GivenName -like $trackuser0 -and Surname -like $trackuser1 } -Properties ipphone
$findusersearch1 | ForEach-Object { $usersearchresult += New-Object psobject -Property @{ 'User ID' = $_.SamAccountName; 'Email Address' = $_.UserPrincipalName; 'Phone Number' = $_.ipPhone } }
}
}
$usersearchresultDB = ConvertTo-DataTable -InputObject $usersearchresult
Update-DataGridView -DataGridView $datagridview15 -Item $usersearchresultDB
}
I am ending up with just the last user in a list of three people that I am testing in $usersearchresult.
Any suggestions would be greatly appreciated. I know the code is wrong somewhere, my brain is just not finding it and fresh eyes would probably snag it in a second. Thanks.
Reading Multiline textbox and output to Datagridview
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Reading Multiline textbox and output to Datagridview
To gather user names why not just use another DataGridView with two columns. Grab the selections and gate all users in one loop into and array then just show them in the grid.
In any case use the search and grid like this to get all results.
In any case use the search and grid like this to get all results.
Code: Select all
$users = Get-ADUser -Filter { GivenName -like $trackuser0 -and Surname -like $trackuser1 } -Properties ipphone |
ForEach-Object {
[pscustomobject]@{
'User ID' = $_.SamAccountName
'Email Address' = $_.UserPrincipalName
'Phone Number' = $_.ipPhone
}
}
$datagridview15.DataSource = ConvertTo-Datable $users