ADLookupLDAPGCWinNTDomainLocalLanman.ps1

<#PSScriptInfo
 
.VERSION 1.0
 
.GUID 0b4c766f-61b9-492b-8f93-9831f0b8202d
 
.AUTHOR John Merager
 
.COMPANYNAME
 
.COPYRIGHT 12/30/2020
 
.TAGS AD, Active Directory, LDAP, GC, WinNT, Services, Shares, User, Users, Account, Accounts, Group, Groups, SG, DL, Members, Lookup, Query, Properties, UserFlags, lanmanserver
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
.PRIVATEDATA
 
#>


<#
 
.DESCRIPTION
 Lookup Active Directory Info/Properties and Local Computer Information such as Users, Groups, Services and Shares
 Features:
 * Querying:
  - GC: Runs GC query if domain not specified (Ex: "MyUser" instead of "domain\MyUser")
  - LDAP: Runs LDAP query when domain specified (Ex: "domain\MyUser" instead of "MyUser")
  - WinNT: Runs WinNT query either in domain or on computer (Ex: "ThisCanBeDomain\User", Ex: "ThisCanBeComputer\User, Ex: "ComputerName")
  - UserFlags: Translates UserFlags names/values (from WinNT) if found in properties
 * Dropdown: String lookup dropdown will save successfully queried values in the dropdown list
 * Query CheckBoxes (below Lookup string)
  - FullName - Searches cn, displayname, and name in AD for string
  - LastName - Searches sn in AD for string
  - Mail - Searches mail, userprincipalname, and mailnickname in AD for string
  - FirstName - Searches givenname in AD for string
  - EmployeeId - Searches employeenumber and employeeid in AD for string
  - Alias - Searches sAMAccountName in AD for string
  - "ExactMatch" - If unchecked, assume partial search and puts wild cards around string for Lookup (Ex: "MyUser" will search like "*MyUser*")
 * Filters: Executes after Lookup so retains unfiltered values. Click on Filter button after Lookup to filter or blank-out filters to unfilter
  - Filter on or exclude string on returned rows (works after search)
  - Specify Columns: Able to specific columns for filter search (Ex: Alias,Name,Value).
  - "Exact" checkbox means match entire string of cell - Unchecked adds wild cards *aroundstring* during filter
  - "Case-Sens" means case sensitive filter
 * Results:
  - Double-Click on Cell: will either lookup that value or open a text window. It depends on the cell column and table
  - Has multiple tabs returned with information Properties and User/Computer/Group (depending on user type)
  - Additional ADInfo: Members, MemberOf, ManagedObjects, ManagedBy, and DirectReports
  - For Local Computer information, it returns Users, Groups, Services and Shares
  - Gets Manager Information
  - Returns a summary of properties from AD for User, Group and Computer. These columns may differ in different domains/companies
 * Checkboxes for Results
  - GetProperties: Show Properties returned from LDAP, GC, WinNT, and UserFlags (from users, groups and computers)
   * Properties can get very large on multiple returns from a lookup and slow on too many
   * Shows UserFlags details in Properties list if UserFlags value is found in Properties
  - "Get Extra Member Details (slower)" - Slow because it runs an additional query for each member returned from a Group, DirectReports, etc...
   * Very slow if there is a large number of members (or multiple results), because it runs an AD query for each member
  - "No extra details on multiple results" - If multiple (for example) groups are returned, it does not query member details (not used if above checkbox is unchecked)
  - MemberOf: Gets members from memberof
  - ManagedBy: Gets members from managedby and msexchcomanagedbylink
  - ManagedObjects: Gets members from managedobjects
  - Members: Gets Group members from member
    * Shows group type: DL (Distribution List/Email), SG Universal, SG Global, and SG Local (Security Groups)
  - DirectReports: Gets members from directreports
 * "AlwaysOnTop" Checkbox puts this in the foreground on top of other applications
 * "Debug" Checkbox - writes to the command prompt - functions which are executed
 * -File parameter to load list for dropdown from text file
 
 NOTE: Some Properties and columns may differ between different companies and different domains
       It is suggested to modify the columns to what you see as important
       For an example of places in the code to change columns, search for "ExampleColumnComputer" in this PowerShell script
 
#>
 
Param([String]$File="")
###############################################################################
### Written By: John Merager #
##############################
### 05/10/2019 - Created this Script for Getting AD Info - Version 1.0 - John Merager
### 12/30/2020 - Updated comments and cleaned up code - John Merager
###
###############################################################################
### Starting
###############################################################################
write-host "Starting...Please Wait..."
###############################################################################
### Error Action
###############################################################################
$ErrorPreference=$script:ErrorActionPreference
###############################################################################
### Default Values
###############################################################################

###############################################################################
### Variables
###############################################################################
$CurrentComputer = ([String]$env:COMPUTERNAME).ToUpper()            # Server Name
$CurrentUser      = ([System.Security.Principal.WindowsIdentity]::GetCurrent()).Name
if ($CurrentUser.contains("\"))
 {$CurrentUserAlias = $CurrentUser.substring($CurrentUser.IndexOf("\")+1,$CurrentUser.length-$CurrentUser.IndexOf("\")-1)}
else
 {$CurrentUserAlias=$CurrentUser}
$Interval = 1                # Refresh Interval (default 1 seconds)
###############################################################################
### Change Time Default Format
###############################################################################
$currentThread = [System.Threading.Thread]::CurrentThread
$culture = [CultureInfo]::InvariantCulture.Clone()
$culture.DateTimeFormat.ShortDatePattern = 'MM/dd/yyyy'
$culture.DateTimeFormat.ShortTimePattern = 'HH:mm:ss'
$currentThread.CurrentCulture = $culture
#$currentThread.CurrentUICulture = $culture
###############################################################################
### Load the .net assembly and Variables
###############################################################################
$global:UserInfoTabs=@()
$global:UserInfoGrids=@()
$global:UserInfoLastFiltered=$False

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
$ToolTip = New-Object System.Windows.Forms.ToolTip

###############################################################################
### General Functions
###############################################################################

###############################################################################
### Functions: Status Bar
###############################################################################
Function ClickChangeTab
{
 if ($chkUserInfoDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 $StatusBar_P1.Text = $global:TabIndexList[$tab.SelectedIndex].Status
 $StatusBar_P2.Text = $global:TabIndexList[$tab.SelectedIndex].Details
 $StatusBar_P3.Text = $global:TabIndexList[$tab.SelectedIndex].Server
}

Function StatusAddToBar($Index)
{
 if ($chkUserInfoDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 if (("$($global:TabIndexList[$Index].Status)").length -lt 50)
  {
   $global:TabIndexList[$Index].Status += "$([char]0x2588)"
   if ($chkUserInfoDebug.Checked) {write-host -NoNewline "."}
  }
 else
  {
   $global:TabIndexList[$Index].Status = "$([char]0x2588)"
   if ($chkUserInfoDebug.Checked) {write-host "."}
  }
 $StatusBar_P1.Text=$global:TabIndexList[$Index].Status
}

Function StatusUpdate($Index,$Status1,$Status2,$Status3)
{
 if ($chkUserInfoDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
    if ($Status1 -ne $null)
     {$global:TabIndexList[$Index].Status = "$Status1"}
    if ($Status2 -ne $null)
     {$global:TabIndexList[$Index].Details = "$Status2"}
    if ($Status3)
     {$global:TabIndexList[$Index].Server = "$Status3"}
    elseif ($Status3 -eq "")
     {$global:TabIndexList[$Index].Server = "$CurrentComputer"}
  if ($Index -eq $tab.SelectedIndex)
   {
    if ($Status1 -ne $null)
     {$StatusBar_P1.Text = "$Status1"}
    if ($Status2 -ne $null)
     {$StatusBar_P2.Text = "$Status2"}
    if ($Status3)
     {$StatusBar_P3.Text = "$Status3"}
    elseif ($Status3 -eq "")
     {$StatusBar_P3.Text = "$CurrentComputer"}
   }
}

###############################################################################
### Functions: Mouse
###############################################################################

Function ShowMouseHoverToolTip
{
 if ($chkUserInfoDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 Switch ($this.name)
  {
   "test1"  {$tip = "Test1"}
   "test2"  {$tip = "Test2"}
   "SyncAutoClear" {$tip = "Clear below table for each new execution"}
    default {$tip = ""}
  }
 $ToolTip.SetToolTip($this,$tip)
}

###############################################################################
### Functions: Date Time
###############################################################################

Function UTCtoLocalTime([DateTime]$UTCTime)
{
 if ($chkUserInfoDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 foreach ($UTC in [System.TimeZoneInfo]::GetSystemTimeZones())
  {
   if ($UTC.Id -eq 'UTC')
    {
     return ($UTCTime).AddMinutes(([DateTime]::Now-[TimeZoneInfo]::ConvertTime([DateTime]::Now, $UTC)).TotalMinutes)
    }
  }
}

Function UTCtoLocalTimeMinutes([DateTime]$UTCTime)
{
 if ($chkUserInfoDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 foreach ($UTC in [System.TimeZoneInfo]::GetSystemTimeZones())
  {
   if ($UTC.Id -eq 'UTC')
    {
     return ([DateTime]::Now-[TimeZoneInfo]::ConvertTime([DateTime]::Now, $UTC)).TotalMinutes
    }
  }
}

Function CurrentUTC
{
 if ($chkUserInfoDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 foreach ($UTC in [System.TimeZoneInfo]::GetSystemTimeZones())
  {
   if ($UTC.Id -eq 'UTC')
    {
     return [TimeZoneInfo]::ConvertTime([DateTime]::Now, $UTC)
    }
  }
}

###############################################################################
### Functions: TextBox
###############################################################################

Function OpenTextBox($TextValue)
{
 if ($chkUserInfoDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
    $subform = new-object System.Windows.Forms.Form  
    $subform.Size = new-object System.Drawing.Size 600,400  
    $OpenTextBox = new-object System.windows.forms.TextBox
    $OpenTextBox.Location = New-Object System.Drawing.Size(0,0)
    $OpenTextBox.Size = New-Object System.Drawing.Size(578,353)
    $OpenTextBox.Multiline=$true
    $TextValue=$TextValue.replace("><",">`r`n<")
    $TextValue=$TextValue.replace(">`n",">`r`n")
    $OpenTextBox.ScrollBars="Vertical"
    #$OpenTextBox.WordWrap=$False
    #$OpenTextBox.ScrollBars="Both"
    $OpenTextBox.Text = "$TextValue"
    $subform.Controls.Add($OpenTextBox)
    $subform.topmost = $true  
    $subform.Add_SizeChanged({OpenTextBoxSizeChanged})
    $subform.showdialog()
}

Function OpenTextBoxSizeChanged
{
 $OpenTextBox.Width=$subform.Width-22
 $OpenTextBox.Height=$subform.Height-47
}

###################################################################
#################### UserInfo Tab Functions

Function ClickUserInfoFilterGo
{
 if ($chkUserInfoDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 $btnUserInfoFilterGo.Enabled=$False
   $FilterOn=("$($tbxUserInfoFilter.Text)").Trim()
   $Exclude=("$($tbxUserInfoExclude.Text)").Trim()
   $FilteredColumns=@()
   if (("$($tbxUserInfoColumns.Text)").Trim() -ne "")
    {
     $DoFilterColumns=$True
     Foreach ($Col in ($tbxUserInfoColumns.Text).split(','))
      {
       $FilteredColumns+=$Col
      }
    }
   else
    {
     $DoFilterColumns=$False
    }
   if ("$FilterOn" -ne "" -Or "$Exclude" -ne "")
    {
     $Filtering=$True
    }
   else
    {
     $DoFilterColumns=$False
     $Filtering=$False
    }
       if ($chkUserInfoFilterExactMatch.Checked)
        {
         $WildCard=""
        }
       else
        {
         $WildCard="*"
        }
  if ($Filtering)
   {
    if (!($global:UserInfoLastFiltered))
     {
      $LastSelectedTabIndex=$tab1.SelectedIndex
      for ($TC=$tab1.controls.Count-1;$TC -gt 0; $TC--)
       {
        If ($TC -ne $LastSelectedTabIndex)
         {
          $tab1.SelectedIndex=$TC
         }
       }
      $tab1.SelectedIndex=$LastSelectedTabIndex
     }
    $global:UserInfoLastFiltered=$True
    foreach ($Grid in $global:UserInfoGrids)
     {
      $GetColumns=@()
      foreach ($Col in $Grid.DataSource.Columns)
       {
        if ($DoFilterColumns -eq $False -Or $FilteredColumns -contains $Col.ColumnName)
         {
          $GetColumns+=$Col.Ordinal
         }
       }
      $Grid.CurrentCell = $null #Unselect cells
      foreach ($DeployRow in $Grid.rows)#$DeployRow.ItemArray
       {
        $DoShowRow=$True
        $FoundFilter=$False
        foreach ($Col in $GetColumns)
         {
          if ("$Exclude" -ne "" -And $DeployRow.DataBoundItem[$Col] -like "$WildCard$($Exclude)$WildCard")
           {
            $DoShowRow=$False
           }
          elseif (($DoShowRow) -And "$FilterOn" -ne "" -And $DeployRow.DataBoundItem[$Col] -like "$WildCard$($FilterOn)$WildCard")
           {
            $FoundFilter=$True
           }
         }
        if (($DoShowRow) -And (!($FoundFilter)) -And "$FilterOn" -ne "")
         {
          $DoShowRow=$False
         }
        if ($DoShowRow)
         {
          $DeployRow.Visible=$True
         }
        else
         {
          $DeployRow.Visible=$False
         }
       }
     }
   }
  elseif ($global:UserInfoLastFiltered)
   {
    $global:UserInfoLastFiltered=$False
    foreach ($Grid in $global:UserInfoGrids)
     {
      foreach ($DeployRow in $Grid.rows)#$DeployRow.ItemArray
       {
        $DeployRow.Visible=$True
       }
     }
   }
 $btnUserInfoFilterGo.Enabled=$True
}

Function ClickUserInfoLookUp($SearchProperty="")
{
 if ($chkUserInfoDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 $btnUserInfoLookUp.Enabled=$False
 StatusUpdate $tab.SelectedIndex "(Checking...) ($(get-date))" $null $null
############################
### Lookup String
############################
$LookupName="$($cbxUserInfoLookUp.Text)"
if ("$LookupName" -eq "")
 {
  Write-host "Please specify a string to lookup in AD"
  return
 }
$SaveLookupName="$LookupName"

############################
### Look for Domains
############################
$Domains=@()
$Domains+=""
if ($LookupName.IndexOf("\") -gt 0)
 {
  $Domains[0]=$LookupName.substring(0,$LookupName.IndexOf("\"))
  $DomainName=$Domains[0]
  if ("$DomainName" -eq ".")
   {
    $DomainName=$Env:COMPUTERNAME
   }
  $LookupName=$LookupName.substring($LookupName.IndexOf("\")+1,$LookupName.length-$LookupName.IndexOf("\")-1)
 }
$LookupMail=$LookupName
if (!($chkUserInfoExactMatch.Checked))
 {
  $LookupName="*$($LookupName)*"
  $LookupMail="*$($LookupMail)*"
 }
############################
### AD Filter
############################
if ("$SearchProperty" -ne "")
 {
  $filter = "($($SearchProperty)=$LookupName)"
 }
else
 {
  $filter = "|"
  if ($chkUserInfoAlias.Checked)
   {
    $filter = "$($filter)(sAMAccountName=$LookupName)"
   }
  if ($chkUserInfoFullName.Checked)
   {
    $filter = "$($filter)(cn=$LookupName)(displayname=$LookupName)(name=$LookupName)"
   }
  if ($chkUserInfoMail.Checked)
   {
    $filter = "$($filter)(mail=$LookupMail)(userprincipalname=$LookupMail)(mailnickname=$LookupName)"
   }
  if ($chkUserInfoEmployeeID.Checked)
   {
    $filter = "$($filter)(employeenumber=$LookupName)(employeeid=$LookupName)"#(description=$LookupName)
   }
  if ($chkUserInfoLastName.Checked)
   {
    $filter = "$($filter)(sn=$LookupName)"
   }
  if ($chkUserInfoFirstName.Checked)
   {
    $filter = "$($filter)(givenname=$LookupName)"
   }
 }
 if ($chkUserInfoDebug.Checked) {write-host "Filter: ($filter)"}

############################
### UserFlags
############################
$UserFlagsList=@()
$UserFlagsList+=New-Object PSObject -Property @{Name="SCRIPT";Value=0x1}
$UserFlagsList+=New-Object PSObject -Property @{Name="DISABLE";Value=0x2}
$UserFlagsList+=New-Object PSObject -Property @{Name="HOMEDIR_REQUIRED";Value=0x8}
$UserFlagsList+=New-Object PSObject -Property @{Name="LOCKED";Value=0x10}
$UserFlagsList+=New-Object PSObject -Property @{Name="PASSWD_NOTREQD";Value=0x20}
$UserFlagsList+=New-Object PSObject -Property @{Name="PASSWD_CANT_CHANGE";Value=0x40}
$UserFlagsList+=New-Object PSObject -Property @{Name="ENCRYPTED_TEXT_PASSWORD_ALLOWED";Value=0x80}
$UserFlagsList+=New-Object PSObject -Property @{Name="TEMP_DUPLICATE_ACCOUNT";Value=0x100}
$UserFlagsList+=New-Object PSObject -Property @{Name="NORMAL_ACCOUNT";Value=0x200}
$UserFlagsList+=New-Object PSObject -Property @{Name="INTERDOMAIN_TRUST_ACCOUNT";Value=0x800}
$UserFlagsList+=New-Object PSObject -Property @{Name="WORKSTATION_TRUST_ACCOUNT";Value=0x1000}
$UserFlagsList+=New-Object PSObject -Property @{Name="SERVER_TRUST_ACCOUNT";Value=0x2000}
$UserFlagsList+=New-Object PSObject -Property @{Name="DONT_EXPIRE_PASSWD";Value=0x10000}
$UserFlagsList+=New-Object PSObject -Property @{Name="MNS_LOGON_ACCOUNT";Value=0x20000}
$UserFlagsList+=New-Object PSObject -Property @{Name="SMARTCARD_REQUIRED";Value=0x40000}
$UserFlagsList+=New-Object PSObject -Property @{Name="TRUSTED_FOR_DELEGATION";Value=0x80000}
$UserFlagsList+=New-Object PSObject -Property @{Name="NOT_DELEGATED";Value=0x100000}
$UserFlagsList+=New-Object PSObject -Property @{Name="USE_DES_KEY_ONLY";Value=0x200000}
$UserFlagsList+=New-Object PSObject -Property @{Name="DONT_REQUIRE_PREAUTH";Value=0x400000}
$UserFlagsList+=New-Object PSObject -Property @{Name="PASSWORD_EXPIRED";Value=0x800000}
<#
            ADS_UF_SCRIPT { $UserFlag += 1 } # 0x1
            ADS_UF_ACCOUNTDISABLE { $UserFlag += 2 } # 0x2
            ADS_UF_HOMEDIR_REQUIRED { $UserFlag += 8 } # 0x8
            ADS_UF_LOCKOUT { $UserFlag += 16 } # 0x10
            ADS_UF_PASSWD_NOTREQD { $UserFlag += 32 } # 0x20
            ADS_UF_PASSWD_CANT_CHANGE { $UserFlag += 64 } # 0x40
            ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED { $UserFlag += 128 } # 0x80
            ADS_UF_TEMP_DUPLICATE_ACCOUNT { $UserFlag += 256 } # 0x100
            ADS_UF_NORMAL_ACCOUNT { $UserFlag += 512 } # 0x200
            ADS_UF_INTERDOMAIN_TRUST_ACCOUNT { $UserFlag += 2048 } # 0x800
            ADS_UF_WORKSTATION_TRUST_ACCOUNT { $UserFlag += 4096 } # 0x1000
            ADS_UF_SERVER_TRUST_ACCOUNT { $UserFlag += 8192 } # 0x2000
            ADS_UF_DONT_EXPIRE_PASSWD { $UserFlag += 65536 } # 0x10000
            ADS_UF_MNS_LOGON_ACCOUNT { $UserFlag += 131072 } # 0x20000
            ADS_UF_SMARTCARD_REQUIRED { $UserFlag += 262144 } # 0x40000
            ADS_UF_TRUSTED_FOR_DELEGATION { $UserFlag += 524288 } # 0x80000
            ADS_UF_NOT_DELEGATED { $UserFlag += 1048576 } # 0x100000
            ADS_UF_USE_DES_KEY_ONLY { $UserFlag += 2097152 } # 0x200000
            ADS_UF_DONT_REQUIRE_PREAUTH { $UserFlag += 4194304 } # 0x400000
            ADS_UF_PASSWORD_EXPIRED { $UserFlag += 8388608 } # 0x800000
            ADS_UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION { $UserFlag += 16777216 } # 0x1000000
#>



############################
### Tables
############################
$TblUserInfoTableResultStatus = New-Object System.Data.DataTable
$TblUserInfoTableResultStatus.TableName = "UserInfoStatus"
[void]$TblUserInfoTableResultStatus.Columns.Add("SearchString",([string]))#,([string])
[void]$TblUserInfoTableResultStatus.Columns.Add("When",([string]))#,([string])
[void]$TblUserInfoTableResultStatus.Columns.Add("Status",([string]))#,([string])

$TblUserInfoTableResultComputerUsers = New-Object System.Data.DataTable
$TblUserInfoTableResultComputerUsers.TableName = "UserInfoUsers"
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("Domain",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("LocalUser",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("FullName",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("SID",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("GUID",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("PwdExpires",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("ExpireDays",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("MaxDays",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("Path",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("BadPwdAttempts",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("NeverExpires",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("CannotChgPwd",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("AcctLocked",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("AcctDisabled",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("PwdExpired",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("UserFlags",([string]))#,([string])
[void]$TblUserInfoTableResultComputerUsers.Columns.Add("Parent",([string]))#,([string])

$TblUserInfoTableResultComputerGroupMembers = New-Object System.Data.DataTable
$TblUserInfoTableResultComputerGroupMembers.TableName = "UserInfoGroupMembers"
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("Domain",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("LocalUser",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("FullName",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("SID",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("GUID",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("PwdExpires",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("ExpireDays",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("MaxDays",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("Path",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("BadPwdAttempts",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("NeverExpires",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("CannotChgPwd",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("AcctLocked",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("AcctDisabled",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("PwdExpired",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("UserFlags",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroupMembers.Columns.Add("Parent",([string]))#,([string])

$TblUserInfoTableResultComputerGroups = New-Object System.Data.DataTable
$TblUserInfoTableResultComputerGroups.TableName = "UserInfoGroups"
[void]$TblUserInfoTableResultComputerGroups.Columns.Add("Domain",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroups.Columns.Add("LocalGroup",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroups.Columns.Add("SID",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroups.Columns.Add("GUID",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroups.Columns.Add("Path",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroups.Columns.Add("Parent",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroups.Columns.Add("Type",([string]))#,([string])
[void]$TblUserInfoTableResultComputerGroups.Columns.Add("Description",([string]))#,([string])

$TblUserInfoTableResultComputerServices = New-Object System.Data.DataTable
$TblUserInfoTableResultComputerServices.TableName = "UserInfoServices"
[void]$TblUserInfoTableResultComputerServices.Columns.Add("Domain",([string]))#,([string])
[void]$TblUserInfoTableResultComputerServices.Columns.Add("Server",([string]))#,([string])
[void]$TblUserInfoTableResultComputerServices.Columns.Add("Name",([string]))#,([string])
[void]$TblUserInfoTableResultComputerServices.Columns.Add("DisplayName",([string]))#,([string])
[void]$TblUserInfoTableResultComputerServices.Columns.Add("ServiceAccountName",([string]))#,([string])
[void]$TblUserInfoTableResultComputerServices.Columns.Add("ServiceType",([string]))#,([string])
[void]$TblUserInfoTableResultComputerServices.Columns.Add("StartType",([string]))#,([string])
[void]$TblUserInfoTableResultComputerServices.Columns.Add("ErrorControl",([string]))#,([string])
[void]$TblUserInfoTableResultComputerServices.Columns.Add("Path",([string]))#,([string])
[void]$TblUserInfoTableResultComputerServices.Columns.Add("GUID",([string]))#,([string])

$TblUserInfoTableResultComputerShares = New-Object System.Data.DataTable
$TblUserInfoTableResultComputerShares.TableName = "UserInfoShares"
[void]$TblUserInfoTableResultComputerShares.Columns.Add("Domain",([string]))#,([string])
[void]$TblUserInfoTableResultComputerShares.Columns.Add("Server",([string]))#,([string])
[void]$TblUserInfoTableResultComputerShares.Columns.Add("Name",([string]))#,([string])
[void]$TblUserInfoTableResultComputerShares.Columns.Add("Path",([string]))#,([string])
[void]$TblUserInfoTableResultComputerShares.Columns.Add("CurrentUserCount",([string]))#,([string])
[void]$TblUserInfoTableResultComputerShares.Columns.Add("Description",([string]))#,([string])
[void]$TblUserInfoTableResultComputerShares.Columns.Add("GUID",([string]))#,([string])
[void]$TblUserInfoTableResultComputerShares.Columns.Add("HostComputer",([string]))#,([string])
[void]$TblUserInfoTableResultComputerShares.Columns.Add("Parent",([string]))#,([string])

$TblUserInfoTableResultProperties = New-Object System.Data.DataTable
$TblUserInfoTableResultProperties.TableName = "UserInfoDetails"
[void]$TblUserInfoTableResultProperties.Columns.Add("Alias",([string]))#,([string])
[void]$TblUserInfoTableResultProperties.Columns.Add("Domain",([string]))#,([string])
[void]$TblUserInfoTableResultProperties.Columns.Add("From",([string]))#,([string])
[void]$TblUserInfoTableResultProperties.Columns.Add("Name",([string]))#,([string])
[void]$TblUserInfoTableResultProperties.Columns.Add("Value",([string]))#,([string])

$TblUserInfoTableResultPerson = New-Object System.Data.DataTable
$TblUserInfoTableResultPerson.TableName = "UserInfoPerson"
[void]$TblUserInfoTableResultPerson.Columns.Add("Alias",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Domain",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("FullName",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Email",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("EmployeeId",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Manager",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Type",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Title",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Mailbox",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Locaiton",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Phone",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("OtherPhone",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Cell",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Facsimile",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("OtherFacsimile",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("msrtcsip-line",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Pager",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Department",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Division",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Company",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Created",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("Description",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("PwdExpires",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("ExpireDays",([string]))#,([string])
[void]$TblUserInfoTableResultPerson.Columns.Add("MaxDays",([string]))#,([string])
#[void]$TblUserInfoTableResultPerson.Columns.Add("Link",([string]))#,([string])
#ENTER to click on button

$TblUserInfoTableResultGroup = New-Object System.Data.DataTable
$TblUserInfoTableResultGroup.TableName = "UserInfoGroup"
[void]$TblUserInfoTableResultGroup.Columns.Add("Alias",([string]))#,([string])
[void]$TblUserInfoTableResultGroup.Columns.Add("Domain",([string]))#,([string])
[void]$TblUserInfoTableResultGroup.Columns.Add("DisplayName",([string]))#,([string])
[void]$TblUserInfoTableResultGroup.Columns.Add("Email",([string]))#,([string])
[void]$TblUserInfoTableResultGroup.Columns.Add("Type",([string]))#,([string])
[void]$TblUserInfoTableResultGroup.Columns.Add("Description",([string]))#,([string])
[void]$TblUserInfoTableResultGroup.Columns.Add("Name",([string]))#,([string])
[void]$TblUserInfoTableResultGroup.Columns.Add("DistinguishedName",([string]))#,([string])

$TblUserInfoTableResultOther = New-Object System.Data.DataTable
$TblUserInfoTableResultOther.TableName = "UserInfoOther"
[void]$TblUserInfoTableResultOther.Columns.Add("cn",([string]))#,([string])
[void]$TblUserInfoTableResultOther.Columns.Add("Domain",([string]))#,([string])
[void]$TblUserInfoTableResultOther.Columns.Add("DisplayName",([string]))#,([string])
[void]$TblUserInfoTableResultOther.Columns.Add("Type",([string]))#,([string])
[void]$TblUserInfoTableResultOther.Columns.Add("Description",([string]))#,([string])
[void]$TblUserInfoTableResultOther.Columns.Add("Name",([string]))#,([string])
[void]$TblUserInfoTableResultOther.Columns.Add("DistinguishedName",([string]))#,([string])

$TblUserInfoTableResultComputer = New-Object System.Data.DataTable
$TblUserInfoTableResultComputer.TableName = "UserInfoComputer"
[void]$TblUserInfoTableResultComputer.Columns.Add("Alias",([string]))#,([string])
[void]$TblUserInfoTableResultComputer.Columns.Add("Domain",([string]))#,([string])
[void]$TblUserInfoTableResultComputer.Columns.Add("Name",([string]))#,([string])
[void]$TblUserInfoTableResultComputer.Columns.Add("cn",([string]))#,([string])
[void]$TblUserInfoTableResultComputer.Columns.Add("Location",([string]))#,([string])
[void]$TblUserInfoTableResultComputer.Columns.Add("FirstName",([string]))#,([string])
[void]$TblUserInfoTableResultComputer.Columns.Add("MI",([string]))#,([string])
[void]$TblUserInfoTableResultComputer.Columns.Add("LastName",([string]))#,([string])
[void]$TblUserInfoTableResultComputer.Columns.Add("EmployeeId",([string]))#,([string])
[void]$TblUserInfoTableResultComputer.Columns.Add("DNSHostname",([string]))#,([string])
[void]$TblUserInfoTableResultComputer.Columns.Add("WhenCreated",([string]))#,([string])
[void]$TblUserInfoTableResultComputer.Columns.Add("Info",([string]))#,([string])
[void]$TblUserInfoTableResultComputer.Columns.Add("DistinguishedName",([string]))#,([string])
#[void]$TblUserInfoTableResultComputer.Columns.Add("ExampleColumnComputer",([string]))#,([string])

$TblUserInfoTableResultMemberOf = New-Object System.Data.DataTable
$TblUserInfoTableResultMemberOf.TableName = "UserInfoMemberOf"
[void]$TblUserInfoTableResultMemberOf.Columns.Add("MemberOfAlias",([string]))#,([string])
[void]$TblUserInfoTableResultMemberOf.Columns.Add("MemberOfDomain",([string]))#,([string])
if ($chkUserInfoGetExtraDetails.Checked)
 {
  [void]$TblUserInfoTableResultMemberOf.Columns.Add("Alias",([string]))#,([string])
  [void]$TblUserInfoTableResultMemberOf.Columns.Add("Domain",([string]))#,([string])
  [void]$TblUserInfoTableResultMemberOf.Columns.Add("DisplayName",([string]))#,([string])
  [void]$TblUserInfoTableResultMemberOf.Columns.Add("Email",([string]))#,([string])
  [void]$TblUserInfoTableResultMemberOf.Columns.Add("Type",([string]))#,([string])
  [void]$TblUserInfoTableResultMemberOf.Columns.Add("Description",([string]))#,([string])
  [void]$TblUserInfoTableResultMemberOf.Columns.Add("Name",([string]))#,([string])
 }
else
 {
  [void]$TblUserInfoTableResultMemberOf.Columns.Add("CN",([string]))#,([string])
  [void]$TblUserInfoTableResultMemberOf.Columns.Add("Domain",([string]))#,([string])
  [void]$TblUserInfoTableResultMemberOf.Columns.Add("Type",([string]))#,([string])
 }
[void]$TblUserInfoTableResultMemberOf.Columns.Add("DistinguishedName",([string]))#,([string])

$TblUserInfoTableResultManagedObjects = New-Object System.Data.DataTable
$TblUserInfoTableResultManagedObjects.TableName = "UserInfoManagedObjects"
[void]$TblUserInfoTableResultManagedObjects.Columns.Add("ManagedByAlias",([string]))#,([string])
[void]$TblUserInfoTableResultManagedObjects.Columns.Add("ManagedByDomain",([string]))#,([string])
if ($chkUserInfoGetExtraDetails.Checked)
 {
  [void]$TblUserInfoTableResultManagedObjects.Columns.Add("Alias",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedObjects.Columns.Add("Domain",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedObjects.Columns.Add("DisplayName",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedObjects.Columns.Add("Email",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedObjects.Columns.Add("Type",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedObjects.Columns.Add("Description",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedObjects.Columns.Add("Name",([string]))#,([string])
 }
else
 {
  [void]$TblUserInfoTableResultManagedObjects.Columns.Add("CN",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedObjects.Columns.Add("Domain",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedObjects.Columns.Add("Type",([string]))#,([string])
 }
[void]$TblUserInfoTableResultManagedObjects.Columns.Add("DistinguishedName",([string]))#,([string])

$TblUserInfoTableResultMembers = New-Object System.Data.DataTable
$TblUserInfoTableResultMembers.TableName = "UserInfoMembers"
[void]$TblUserInfoTableResultMembers.Columns.Add("MemberOfAlias",([string]))#,([string])
[void]$TblUserInfoTableResultMembers.Columns.Add("MemberOfDomain",([string]))#,([string])
if ($chkUserInfoGetExtraDetails.Checked)
 {
  [void]$TblUserInfoTableResultMembers.Columns.Add("Alias",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Domain",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("FullName",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Email",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("EmployeeId",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Manager",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Type",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Mailbox",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Locaiton",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Phone",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("OtherPhone",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Cell",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Facsimile",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("OtherFacsimile",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("msrtcsip-line",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Pager",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Department",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Company",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Description",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Name",([string]))#,([string])
 }
else
 {
  [void]$TblUserInfoTableResultMembers.Columns.Add("CN",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Domain",([string]))#,([string])
  [void]$TblUserInfoTableResultMembers.Columns.Add("Type",([string]))#,([string])
 }
[void]$TblUserInfoTableResultMembers.Columns.Add("DistinguishedName",([string]))#,([string])

$TblUserInfoTableResultManagedBy = New-Object System.Data.DataTable
$TblUserInfoTableResultManagedBy.TableName = "UserInfoManagedBy"
[void]$TblUserInfoTableResultManagedBy.Columns.Add("ManagedAlias",([string]))#,([string])
[void]$TblUserInfoTableResultManagedBy.Columns.Add("ManagedDomain",([string]))#,([string])
[void]$TblUserInfoTableResultManagedBy.Columns.Add("By",([string]))#,([string])
if ($chkUserInfoGetExtraDetails.Checked)
 {
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Alias",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Domain",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("FullName",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Email",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("EmployeeId",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Manager",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Type",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Mailbox",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Locaiton",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Phone",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("OtherPhone",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Cell",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Facsimile",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("OtherFacsimile",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("msrtcsip-line",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Pager",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Department",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Company",([string]))#,([string])

 }
else
 {
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("CN",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Domain",([string]))#,([string])
  [void]$TblUserInfoTableResultManagedBy.Columns.Add("Type",([string]))#,([string])
 }
[void]$TblUserInfoTableResultManagedBy.Columns.Add("DistinguishedName",([string]))#,([string])

$TblUserInfoTableResultDirectReports = New-Object System.Data.DataTable
$TblUserInfoTableResultDirectReports.TableName = "UserInfoDirectReports"
[void]$TblUserInfoTableResultDirectReports.Columns.Add("ReportToAlias",([string]))#,([string])
[void]$TblUserInfoTableResultDirectReports.Columns.Add("ReportToDomain",([string]))#,([string])
if ($chkUserInfoGetExtraDetails.Checked)
 {
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Alias",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Domain",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("FullName",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Email",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("EmployeeId",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Manager",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Type",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Mailbox",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Locaiton",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Phone",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("OtherPhone",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Cell",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Facsimile",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("OtherFacsimile",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("msrtcsip-line",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Pager",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Department",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Company",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Description",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Name",([string]))#,([string])
 }
else
 {
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("CN",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Domain",([string]))#,([string])
  [void]$TblUserInfoTableResultDirectReports.Columns.Add("Type",([string]))#,([string])
 }
[void]$TblUserInfoTableResultDirectReports.Columns.Add("DistinguishedName",([string]))#,([string])

$FoundTabNames=@()

$TCStart=0
$FoundMemberOf=$False
foreach ($Domain in $Domains)
 {
  $ResultList=@()
  if ($Domain -ne "")
   {
############################
### LDAP Lookup for Domain
############################
    $ADQueryType="LDAP"
    $tempCounters="LDAP:"
    $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
    $Searcher.Filter = "($filter)"
    $Searcher.SearchRoot = (New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$Domain")
    Try {
      $ResultList+=($Searcher.FindOne()).Properties
     } Catch {
      write-host "LDAP://$Domain - Returned: $($Error[0])"
      StatusUpdate $tab.SelectedIndex "(Error: LDAP://$Domain - Returned: $($Error[0])) ($(get-date))" $null $null
      $tempCounters+=" Error"
     }
   }
  else
   {
############################
### Global Catalog Lookup for no domain
############################
    $ADQueryType="GC"
    $tempCounters="GC:"
    #$filter = "(&(objectCategory=person)(objectClass=person)(sAMAccountName=$LookupName))"
    #$filter = "(sAMAccountName=$LookupName)"
    $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
    $Searcher.Filter = "($filter)"
    Try {
      $CurrentDomain="$((([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Name).replace('.',',DC='))"
     } Catch {
      $CurrentDomain=""
      write-host "GC://$CurrentDomain - Error getting forest: $($Error[0])"
      StatusUpdate $tab.SelectedIndex "(Error: GC:// - Returned: $($Error[0])) ($(get-date))" $null $null
      $tempCounters+=" Error"
     }
    if ("$CurrentDomain" -ne "")
     {
      $Searcher.SearchRoot = (New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "GC://DC=$($CurrentDomain)")
      $ResultList+=($Searcher.FindAll()).Properties
     }
    #$ResultList+=([adsisearcher]$filter).FindAll().Properties
   }
############################
### Check Results - TO DO: This could be done better. Review this code later to make code more dense
############################
  if ($ResultList -ne $null -And $ResultList.Count -gt 0)
   {
    if ("$SaveLookupName" -ne "")
     {
      if ($cbxUserInfoLookUp.Items -notcontains "$SaveLookupName")
       {
         [void] $cbxUserInfoLookUp.Items.Add("$SaveLookupName")
       }
     }
    foreach ($Result in $ResultList)
     {
      $Manager=$null
      $UserInfo=$null
      if ($Result.count -gt 0)
       {
        $DomainName=""
        if ("$($Result.distinguishedname)" -ne "")
         {
          foreach ($DomainItem in $Result.distinguishedname.split(","))
           {
            if ($DomainItem.split("=")[0] -eq "DC")
             {
              $DomainName+="$($DomainItem.split("=")[1])."
             }
           }
          if ($DomainName.length -gt 1)
           {
            $DomainName=$DomainName.substring(0,$DomainName.length-1)
           }
         }
        if ("$DomainName" -eq "")
         {
          $DomainName=$Domain
         }
        $UserInfo=([ADSI]("WinNT://$DomainName/$($Result.samaccountname)"))
        if ("$($Result.manager)" -ne "")
         {
          $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
          $Searcher.Filter = "(distinguishedName=*)"
          $Searcher.SearchRoot = (New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$($Result.manager)")
          try {
            $Manager=($Searcher.FindOne()).Properties
           } Catch {
            $Manager=$null
           }
         }
        $UserType=((("$($Result.objectcategory),CN=").replace("CN=","")).split(","))[0]
        if ("$UserType" -eq "Group")
         {
          if ($Result.grouptype -eq 8)
           {
            $UserType="DL"
           }
          elseif ($Result.grouptype -eq 4)
           {
            $UserType="Disabled"
           }
          elseif ($Result.grouptype -eq -2147483640)
           {
            $UserType="SG Universal"
           }
          elseif ($Result.grouptype -eq -2147483646)
           {
            $UserType="SG Global"
           }
          elseif ($Result.grouptype -eq -2147483644)
           {
            $UserType="SG Local"
           }
         }
        $GetPasswordChange="$([datetime]::fromFileTime("$($Result.pwdlastset)"))"
       }
      if ($UserType -eq "Person")
       {
        $DisplayName="$($Result.displayname)"
        if ("$DisplayName" -eq "")
         {
          $DisplayName="$($Result.cn)"
         }
        $MaxDaysToExpire=([int]"$($UserInfo.MaxPasswordAge)") / (60 * 60 * 24)
        $PwdDaysToExpire=[int]((([int]"$($UserInfo.MaxPasswordAge)")-([int]"$($UserInfo.PasswordAge)")) / (60 * 60 * 24))
        $GetPasswordChange="$([datetime]::fromFileTime("$($Result.pwdlastset)"))"
        $PasswordExpires=(get-date $GetPasswordChange).AddSeconds(([int]"$($UserInfo.MaxPasswordAge)"))
        $TblUserInfoTableResultPerson.Rows.Add("$($Result.samaccountname)",$DomainName,"$DisplayName","$($Result.mail)","$($Result.employeenumber)","$($Manager.displayname)","$UserType","$($Result.title)","$($Result.extensionattribute1)","$($Result.physicaldeliveryofficename) $($Result.l) $($Result.st) $($Result.c) $($Result.co)","$($Result.telephonenumber)","$($Result.othertelephone)","$($Result.mobile)","$($Result.facsimiletelephonenumber)","$($Result.otherfacsimiletelephonenumber)","$($Result.'msrtcsip-line')","$($Result.pager)","$($Result.department)","$($Result.division)","$($Result.company)","$($Result.whencreated)","$($Result.description)","$PasswordExpires","$PwdDaysToExpire","$MaxDaysToExpire")#,"https://websiteExample?id=$($Result.employeenumber)"
        if ($FoundTabNames -notcontains "User") {$FoundTabNames+="User"}
       }
      elseif ($UserType -eq "Computer")
       {
        $DisplayName="$($Result.displayname)"
        if ("$DisplayName" -eq "")
         {
          $DisplayName="$($Result.cn)"
         }
        $TblUserInfoTableResultComputer.Rows.Add("$($Result.samaccountname)",$DomainName,"$($Result.name)","$($Result.cn)","$($Result.physicaldeliveryofficename)","$($Result.givenname)","$($Result.initials)","$($Result.sn)","$($Result.employeenumber)","$($Result.dnshostname)","$($Result.whencreated)","$($Result.extensionattribute3)","$($Result.distinguishedname)") #,"$($Result.ExampleColumnComputer)"
        if ($FoundTabNames -notcontains "Computer") {$FoundTabNames+="Computer"}
        $GetTheseItems=@()
        if ($chkUserInfoComputerUsers.Checked) {$GetTheseItems+="User"}
        if ($chkUserInfoComputerGroups.Checked) {$GetTheseItems+="Group"}
        if ($chkUserInfoComputerServices.Checked) {$GetTheseItems+="Service"}
        $UserInfo=([ADSI]("WinNT://$($Result.name)"))
        if ($GetTheseItems.count -gt 0)
         {
          foreach ($Item in ($UserInfo.Children | where {$GetTheseItems -Contains $_.SchemaClassName}))
           {
            if ($Item.SchemaClassName -eq "User")
             {
              $MaxDaysToExpire=([int]"$($Item.MaxPasswordAge)") / (60 * 60 * 24)
              $PwdDaysToExpire=[int]((([int]"$($Item.MaxPasswordAge)")-([int]"$($Item.PasswordAge)")) / (60 * 60 * 24))
              $PasswordExpires=(get-date).AddSeconds((([int]"$($Item.MaxPasswordAge)")-([int]"$($Item.PasswordAge)")))
              if ($Item.UserFlags[0] -band 0x10000)#Never Expires
               {
                $PwdNeverExpires=$True
               }
              else
               {
                $PwdNeverExpires=$False
               }
              if ($Item.UserFlags[0] -band 0x40)#Cannot Change
               {
                $PwdCannotChange=$True
               }
              else
               {
                $PwdCannotChange=$False
               }
              if ($Item.UserFlags[0] -band 0x10)#Locked
               {
                $AccountLocked=$True
               }
              else
               {
                $AccountLocked=$False
               }
              if ($Item.UserFlags[0] -band 0x2)#Disabled
               {
                $AccountDisabled=$True
               }
              else
               {
                $AccountDisabled=$False
               }
              if ($Item.UserFlags[0] -band 0x800000)#Expired
               {
                $PwdExpired=$True
               }
              else
               {
                $PwdExpired=$False
               }
              $TblUserInfoTableResultComputerUsers.Rows.Add("$DomainName","$($Result.name)\$($Item.Name)","$($Item.FullName)","$((New-Object System.Security.Principal.SecurityIdentifier($Item.objectSid[0],0)).value)","$($Item.GUID)","$PasswordExpires","$PwdDaysToExpire","$MaxDaysToExpire","$($Item.Path)","$($Item.BadPasswordAttempts)",$PwdNeverExpires,$PwdCannotChange,$AccountLocked,$AccountDisabled,$PwdExpired,"$($Item.UserFlags)","$($Item.Parent)")
              if ($FoundTabNames -notcontains "LocalUsers") {$FoundTabNames+="LocalUsers"}
             }
            elseif ($Item.SchemaClassName -eq "Group")
             {
              $TblUserInfoTableResultComputerGroups.Rows.Add("$DomainName","$($Result.name)\$($Item.Name)","$((New-Object System.Security.Principal.SecurityIdentifier($Item.objectSid[0],0)).value)","$($Item.GUID)","$($Item.Path)","$($Item.Parent)","$($Item.groupType)","$($Item.Description)")
              if ($FoundTabNames -notcontains "LocalGroups") {$FoundTabNames+="LocalGroups"}
             }
            elseif ($Item.SchemaClassName -eq "Service")
             {
              $TblUserInfoTableResultComputerServices.Rows.Add("$DomainName","$($Result.name)","$($Item.Name)","$($Item.DisplayName)","$($Item.ServiceAccountName)","$($Item.ServiceType)","$($Item.StartType)","$($Item.ErrorControl)","$($Item.Path)","$($Item.GUID)")
              if ($FoundTabNames -notcontains "Services") {$FoundTabNames+="Services"}
             }
           }
         }
        if ($chkUserInfoComputerShares.Checked)
         {
          $UserInfo=([ADSI]("WinNT://$($Result.name)/lanmanserver"))
          $GetTheseItems=@()
          $GetTheseItems+="FileShare"
          foreach ($Item in ($UserInfo.Children |where {$GetTheseItems -Contains $_.SchemaClassName}))
           {
            if ($Item.SchemaClassName -eq "FileShare")
             {
              $TblUserInfoTableResultComputerShares.Rows.Add("$DomainName","$($Result.name)","$($Item.Name)","$($Item.Path)","$($Item.CurrentUserCount)","$($Item.Description)","$($Item.GUID)","$($Item.HostComputer)","$($Item.Parent)")
              if ($FoundTabNames -notcontains "Shares") {$FoundTabNames+="Shares"}
             }
           }
         }
       }
      elseif ($UserType -eq "Group")
       {
        $DisplayName="$($Result.displayname)"
        if ("$DisplayName" -eq "")
         {
          $DisplayName="$($Result.cn)"
         }
        $TblUserInfoTableResultGroup.Rows.Add("$($Result.samaccountname)",$DomainName,"$DisplayName","$($Result.mail)","$UserType","$($Result.description)","$($Result.name)","$($Result.distinguishedname)")
        if ($FoundTabNames -notcontains "Group") {$FoundTabNames+="Group"}
       }
      else
       {
        $DisplayName="$($Result.displayname)"
        if ("$DisplayName" -eq "")
         {
          $DisplayName="$($Result.cn)"
         }
        $TblUserInfoTableResultOther.Rows.Add("$($Result.cn)",$DomainName,"$DisplayName","$UserType","$($Result.description)","$($Result.name)","$($Result.distinguishedname)")
        if ($FoundTabNames -notcontains "Other") {$FoundTabNames+="Other"}
       }
      if (($chkUserInfoSingleReturn.Checked -eq $False -Or $ResultList.count -eq 1) -And $chkUserInfoMemberOf.Checked -eq $True)
       {
      foreach ($Item in ($Result.memberof))
       {
        if ($chkUserInfoGetExtraDetails.Checked)
         {
          $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
          $Searcher.Filter = "(distinguishedName=*)"
          $Searcher.SearchRoot = (New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$($Item)")
          try {
            $ADItem=($Searcher.FindOne()).Properties
           } Catch {
            $ADItem=$null
           }
          $SearchDomain=""
        if ("$($ADItem.distinguishedname)" -ne "")
         {
          foreach ($DomainItem in $ADItem.distinguishedname.split(","))
           {
            if ($DomainItem.split("=")[0] -eq "DC")
             {
              $SearchDomain+="$($DomainItem.split("=")[1])."
             }
           }
          if ($SearchDomain.length -gt 1)
           {
            $SearchDomain=$SearchDomain.substring(0,$SearchDomain.length-1)
           }
          $UserType=((("$($ADItem.objectcategory),CN=").replace("CN=","")).split(","))[0]
          if ("$UserType" -eq "Group")
           {
            if ($ADItem.grouptype -eq 8)
             {
              $UserType="DL"
             }
            elseif ($ADItem.grouptype -eq 4)
             {
              $UserType="Disabled"
             }
            elseif ($ADItem.grouptype -eq -2147483640)
             {
              $UserType="SG Universal"
             }
            elseif ($ADItem.grouptype -eq -2147483646)
             {
              $UserType="SG Global"
             }
            elseif ($ADItem.grouptype -eq -2147483644)
             {
              $UserType="SG Local"
             }
           }
          $DisplayName="$($ADItem.displayname)"
          if ("$DisplayName" -eq "")
           {
            $DisplayName="$($ADItem.cn)"
           }
          $TblUserInfoTableResultMemberOf.Rows.Add("$($Result.samaccountname)",$DomainName,"$($ADItem.samaccountname)","$SearchDomain","$DisplayName","$($ADItem.mail)","$UserType","$($ADItem.description)","$($ADItem.name)","$Item")
          if ($FoundTabNames -notcontains "MemberOf") {$FoundTabNames+="MemberOf"}
         }
         }
        else
         {
          $LastProp=""
          $PropCN=""
          $PropOU=""
          $PropDC=""
          foreach ($ADItem in ("$Item").split(','))
           {
            if ("$ADItem" -like "*\")
             {
              $ADItem=$ADItem.substring(0,$ADItem.length-1)
             }
            if ($ADItem -like "CN=*" -And "$PropCN" -eq "")
             {
              $LastProp=$ADItem.substring(0,2)
              $PropCN=$ADItem.substring(3,$ADItem.length-3)
             }
            elseif ($ADItem -like "OU=*" -And $PropOU -ne "DL" -And ("$PropOU" -eq "" -or @("Distribution Lists","Groups") -contains "$($ADItem.substring(3,$ADItem.length-3))"))
             {
              $LastProp=$ADItem.substring(0,2)
              $PropOU=$ADItem.substring(3,$ADItem.length-3).replace('Distribution Lists','DL').replace('Groups','SG')
             }
            elseif ($ADItem -like "DC=*")
             {
              $LastProp=$ADItem.substring(0,2)
              $PropDC+="$($ADItem.substring(3,$ADItem.length-3))."
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "CN")
             {
              $PropCN+=",$($ADItem)"
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "OU")
             {
              $PropOU+=",$($ADItem)"
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "DC")
             {
              $PropDC+=",$($ADItem)"
             }
           }
          if ("$PropDC" -like "*.")
           {
            $PropDC=$PropDC.substring(0,$PropDC.length-1)
           }
          $TblUserInfoTableResultMemberOf.Rows.Add("$($Result.samaccountname)",$DomainName,"$PropCN","$PropDC","$PropOU","$Item")
          if ($FoundTabNames -notcontains "MemberOf") {$FoundTabNames+="MemberOf"}
         }
       }
       }
      if (($chkUserInfoSingleReturn.Checked -eq $False -Or $ResultList.count -eq 1) -And $chkUserInfoManagedBy.Checked -eq $True)
       {
      foreach ($Item in ($Result.managedby))
       {
        if ($chkUserInfoGetExtraDetails.Checked)
         {
        $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
        $Searcher.Filter = "(distinguishedName=*)"
        $Searcher.SearchRoot = (New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$($Item)")
        try {
          $ADItem=($Searcher.FindOne()).Properties
         } Catch {
          $ADItem=$null
         }
        $SearchDomain=""
        if ("$($ADItem.distinguishedname)" -ne "")
         {
          foreach ($DomainItem in $ADItem.distinguishedname.split(","))
           {
            if ($DomainItem.split("=")[0] -eq "DC")
             {
              $SearchDomain+="$($DomainItem.split("=")[1])."
             }
           }
          if ($SearchDomain.length -gt 1)
           {
            $SearchDomain=$SearchDomain.substring(0,$SearchDomain.length-1)
           }
         }
        $SearchManager=$null
        if ("$($ADItem.manager)" -ne "")
         {
          $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
          $Searcher.Filter = "(distinguishedName=*)"
          $Searcher.SearchRoot = (New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$($ADItem.manager)")
          try {
            $SearchManager=($Searcher.FindOne()).Properties
           } Catch {
            $SearchManager=$null
           }
         }
        $UserType=((("$($ADItem.objectcategory),CN=").replace("CN=","")).split(","))[0]
        if ("$UserType" -eq "Group")
         {
          if ($ADItem.grouptype -eq 8)
           {
            $UserType="DL"
           }
          elseif ($ADItem.grouptype -eq 4)
           {
            $UserType="Disabled"
           }
          elseif ($ADItem.grouptype -eq -2147483640)
           {
            $UserType="SG Universal"
           }
          elseif ($ADItem.grouptype -eq -2147483646)
           {
            $UserType="SG Global"
           }
          elseif ($ADItem.grouptype -eq -2147483644)
           {
            $UserType="SG Local"
           }
         }
        $DisplayName="$($ADItem.displayname)"
        if ("$DisplayName" -eq "")
         {
          $DisplayName="$($ADItem.cn)"
         }
          $TblUserInfoTableResultManagedBy.Rows.Add("$($Result.samaccountname)","$DomainName","$ADQueryType","$($ADItem.samaccountname)","$SearchDomain","$DisplayName","$($ADItem.mail)","$($ADItem.employeenumber)","$($SearchManager.displayname)","$UserType","$($ADItem.extensionattribute1)","$($ADItem.physicaldeliveryofficename) $($ADItem.l) $($ADItem.st) $($ADItem.c) $($ADItem.co)","$($ADItem.telephonenumber)","$($ADItem.othertelephone)","$($ADItem.mobile)","$($ADItem.facsimiletelephonenumber)","$($ADItem.otherfacsimiletelephonenumber)","$($ADItem.'msrtcsip-line')","$($ADItem.pager)","$($ADItem.department)","$($ADItem.company)","$Item")
         }
        else
         {
          $LastProp=""
          $PropCN=""
          $PropOU=""
          $PropDC=""
          foreach ($ADItem in ("$Item").split(','))
           {
            if ("$ADItem" -like "*\")
             {
              $ADItem=$ADItem.substring(0,$ADItem.length-1)
             }
            if ($ADItem -like "CN=*" -And "$PropCN" -eq "")
             {
              $LastProp=$ADItem.substring(0,2)
              $PropCN=$ADItem.substring(3,$ADItem.length-3)
             }
            elseif ($ADItem -like "OU=*" -And $PropOU -ne "DL" -And ("$PropOU" -eq "" -or @("Distribution Lists","Groups") -contains "$($ADItem.substring(3,$ADItem.length-3))"))
             {
              $LastProp=$ADItem.substring(0,2)
              $PropOU=$ADItem.substring(3,$ADItem.length-3).replace('Distribution Lists','DL').replace('Groups','SG')
             }
            elseif ($ADItem -like "DC=*")
             {
              $LastProp=$ADItem.substring(0,2)
              $PropDC+="$($ADItem.substring(3,$ADItem.length-3))."
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "CN")
             {
              $PropCN+=",$($ADItem)"
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "OU")
             {
              $PropOU+=",$($ADItem)"
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "DC")
             {
              $PropDC+=",$($ADItem)"
             }
           }
          if ("$PropDC" -like "*.")
           {
            $PropDC=$PropDC.substring(0,$PropDC.length-1)
           }
          $TblUserInfoTableResultManagedBy.Rows.Add("$($Result.samaccountname)","$DomainName","$ADQueryType","$PropCN","$PropDC","$PropOU","$Item")
         }
        if ($FoundTabNames -notcontains "ManagedBy") {$FoundTabNames+="ManagedBy"}
       }
       }
      if (($chkUserInfoSingleReturn.Checked -eq $False -Or $ResultList.count -eq 1) -And $chkUserInfoManagedBy.Checked -eq $True)
       {
      foreach ($Item in ($Result.msexchcomanagedbylink))
       {
        if ($chkUserInfoGetExtraDetails.Checked)
         {
        $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
        $Searcher.Filter = "(distinguishedName=*)"
        $Searcher.SearchRoot = (New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$($Item)")
        try {
          $ADItem=($Searcher.FindOne()).Properties
         } Catch {
          $ADItem=$null
         }
        $SearchDomain=""
        if ("$($ADItem.distinguishedname)" -ne "")
         {
          foreach ($DomainItem in $ADItem.distinguishedname.split(","))
           {
            if ($DomainItem.split("=")[0] -eq "DC")
             {
              $SearchDomain+="$($DomainItem.split("=")[1])."
             }
           }
          if ($SearchDomain.length -gt 1)
           {
            $SearchDomain=$SearchDomain.substring(0,$SearchDomain.length-1)
           }
         }
        $SearchManager=$null
        if ("$($ADItem.manager)" -ne "")
         {
          $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
          $Searcher.Filter = "(distinguishedName=*)"
          $Searcher.SearchRoot = (New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$($ADItem.manager)")
          try {
            $SearchManager=($Searcher.FindOne()).Properties
           } Catch {
            $SearchManager=$null
           }
         }
        $UserType=((("$($ADItem.objectcategory),CN=").replace("CN=","")).split(","))[0]
        if ("$UserType" -eq "Group")
         {
          if ($ADItem.grouptype -eq 8)
           {
            $UserType="DL"
           }
          elseif ($ADItem.grouptype -eq 4)
           {
            $UserType="Disabled"
           }
          elseif ($ADItem.grouptype -eq -2147483640)
           {
            $UserType="SG Universal"
           }
          elseif ($ADItem.grouptype -eq -2147483646)
           {
            $UserType="SG Global"
           }
          elseif ($ADItem.grouptype -eq -2147483644)
           {
            $UserType="SG Local"
           }
         }
        $DisplayName="$($ADItem.displayname)"
        if ("$DisplayName" -eq "")
         {
          $DisplayName="$($ADItem.cn)"
         }
          $TblUserInfoTableResultManagedBy.Rows.Add("$($Result.samaccountname)","$DomainName","Exch","$($ADItem.samaccountname)","$SearchDomain","$DisplayName","$($ADItem.mail)","$($ADItem.employeenumber)","$($SearchManager.displayname)","$UserType","$($ADItem.extensionattribute1)","$($ADItem.physicaldeliveryofficename) $($ADItem.l) $($ADItem.st) $($ADItem.c) $($ADItem.co)","$($ADItem.telephonenumber)","$($ADItem.othertelephone)","$($ADItem.mobile)","$($ADItem.facsimiletelephonenumber)","$($ADItem.otherfacsimiletelephonenumber)","$($ADItem.'msrtcsip-line')","$($ADItem.pager)","$($ADItem.department)","$($ADItem.company)","$Item")
         }
        else
         {
          $LastProp=""
          $PropCN=""
          $PropOU=""
          $PropDC=""
          foreach ($ADItem in ("$Item").split(','))
           {
            if ("$ADItem" -like "*\")
             {
              $ADItem=$ADItem.substring(0,$ADItem.length-1)
             }
            if ($ADItem -like "CN=*" -And "$PropCN" -eq "")
             {
              $LastProp=$ADItem.substring(0,2)
              $PropCN=$ADItem.substring(3,$ADItem.length-3)
             }
            elseif ($ADItem -like "OU=*" -And $PropOU -ne "DL" -And ("$PropOU" -eq "" -or @("Distribution Lists","Groups") -contains "$($ADItem.substring(3,$ADItem.length-3))"))
             {
              $LastProp=$ADItem.substring(0,2)
              $PropOU=$ADItem.substring(3,$ADItem.length-3).replace('Distribution Lists','DL').replace('Groups','SG')
             }
            elseif ($ADItem -like "DC=*")
             {
              $LastProp=$ADItem.substring(0,2)
              $PropDC+="$($ADItem.substring(3,$ADItem.length-3))."
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "CN")
             {
              $PropCN+=",$($ADItem)"
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "OU")
             {
              $PropOU+=",$($ADItem)"
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "DC")
             {
              $PropDC+=",$($ADItem)"
             }
           }
          if ("$PropDC" -like "*.")
           {
            $PropDC=$PropDC.substring(0,$PropDC.length-1)
           }
          $TblUserInfoTableResultManagedBy.Rows.Add("$($Result.samaccountname)","$DomainName","Exch","$PropCN","$PropDC","$PropOU","$Item")
         }
        if ($FoundTabNames -notcontains "ManagedBy") {$FoundTabNames+="ManagedBy"}
       }
       }
      if (($chkUserInfoSingleReturn.Checked -eq $False -Or $ResultList.count -eq 1) -And $chkUserInfoManagedObjects.Checked -eq $True)
       {
      foreach ($Item in ($Result.managedobjects))
       {
        if ($chkUserInfoGetExtraDetails.Checked)
         {
        $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
        $Searcher.Filter = "(distinguishedName=*)"
        $Searcher.SearchRoot = (New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$($Item)")
        try {
          $ADItem=($Searcher.FindOne()).Properties
         } Catch {
          $ADItem=$null
         }
        $SearchDomain=""
        if ("$($ADItem.distinguishedname)" -ne "")
         {
          foreach ($DomainItem in $ADItem.distinguishedname.split(","))
           {
            if ($DomainItem.split("=")[0] -eq "DC")
             {
              $SearchDomain+="$($DomainItem.split("=")[1])."
             }
           }
          if ($SearchDomain.length -gt 1)
           {
            $SearchDomain=$SearchDomain.substring(0,$SearchDomain.length-1)
           }
         }
        $UserType=((("$($ADItem.objectcategory),CN=").replace("CN=","")).split(","))[0]
        if ("$UserType" -eq "Group")
         {
          if ($ADItem.grouptype -eq 8)
           {
            $UserType="DL"
           }
          elseif ($ADItem.grouptype -eq 4)
           {
            $UserType="Disabled"
           }
          elseif ($ADItem.grouptype -eq -2147483640)
           {
            $UserType="SG Universal"
           }
          elseif ($ADItem.grouptype -eq -2147483646)
           {
            $UserType="SG Global"
           }
          elseif ($ADItem.grouptype -eq -2147483644)
           {
            $UserType="SG Local"
           }
         }
        $DisplayName="$($ADItem.displayname)"
        if ("$DisplayName" -eq "")
         {
          $DisplayName="$($ADItem.cn)"
         }
          $TblUserInfoTableResultManagedObjects.Rows.Add("$($Result.samaccountname)",$DomainName,"$($ADItem.samaccountname)","$SearchDomain","$DisplayName","$($ADItem.mail)","$UserType","$($ADItem.description)","$($ADItem.name)","$Item")
         }
        else
         {
          $LastProp=""
          $PropCN=""
          $PropOU=""
          $PropDC=""
          foreach ($ADItem in ("$Item").split(','))
           {
            if ("$ADItem" -like "*\")
             {
              $ADItem=$ADItem.substring(0,$ADItem.length-1)
             }
            if ($ADItem -like "CN=*" -And "$PropCN" -eq "")
             {
              $LastProp=$ADItem.substring(0,2)
              $PropCN=$ADItem.substring(3,$ADItem.length-3)
             }
            elseif ($ADItem -like "OU=*" -And $PropOU -ne "DL" -And ("$PropOU" -eq "" -or @("Distribution Lists","Groups") -contains "$($ADItem.substring(3,$ADItem.length-3))"))
             {
              $LastProp=$ADItem.substring(0,2)
              $PropOU=$ADItem.substring(3,$ADItem.length-3).replace('Distribution Lists','DL').replace('Groups','SG')
             }
            elseif ($ADItem -like "DC=*")
             {
              $LastProp=$ADItem.substring(0,2)
              $PropDC+="$($ADItem.substring(3,$ADItem.length-3))."
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "CN")
             {
              $PropCN+=",$($ADItem)"
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "OU")
             {
              $PropOU+=",$($ADItem)"
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "DC")
             {
              $PropDC+=",$($ADItem)"
             }
           }
          if ("$PropDC" -like "*.")
           {
            $PropDC=$PropDC.substring(0,$PropDC.length-1)
           }
          $TblUserInfoTableResultManagedObjects.Rows.Add("$($Result.samaccountname)",$DomainName,"$PropCN","$PropDC","$PropOU","$Item")
         }
        if ($FoundTabNames -notcontains "ManagedObjects") {$FoundTabNames+="ManagedObjects"}
       }
       }
      if (($chkUserInfoSingleReturn.Checked -eq $False -Or $ResultList.count -eq 1) -And $chkUserInfoMembers.Checked -eq $True)
       {
      foreach ($Item in ($Result.member))
       {
        if ($chkUserInfoGetExtraDetails.Checked)
         {
        $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
        $Searcher.Filter = "(distinguishedName=*)"
        $Searcher.SearchRoot = (New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$($Item)")
        try {
          $ADItem=($Searcher.FindOne()).Properties
         } Catch {
          $ADItem=$null
         }
        $SearchDomain=""
        if ("$($ADItem.distinguishedname)" -ne "")
         {
          foreach ($DomainItem in $ADItem.distinguishedname.split(","))
           {
            if ($DomainItem.split("=")[0] -eq "DC")
             {
              $SearchDomain+="$($DomainItem.split("=")[1])."
             }
           }
          if ($SearchDomain.length -gt 1)
           {
            $SearchDomain=$SearchDomain.substring(0,$SearchDomain.length-1)
           }
         }
        $SearchManager=$null
        if ("$($ADItem.manager)" -ne "")
         {
          $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
          $Searcher.Filter = "(distinguishedName=*)"
          $Searcher.SearchRoot = (New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$($ADItem.manager)")
          try {
            $SearchManager=($Searcher.FindOne()).Properties
           } Catch {
            $SearchManager=$null
           }
         }
        $UserType=((("$($ADItem.objectcategory),CN=").replace("CN=","")).split(","))[0]
        if ("$UserType" -eq "Group")
         {
          if ($ADItem.grouptype -eq 8)
           {
            $UserType="DL"
           }
          elseif ($ADItem.grouptype -eq 4)
           {
            $UserType="Disabled"
           }
          elseif ($ADItem.grouptype -eq -2147483640)
           {
            $UserType="SG Universal"
           }
          elseif ($ADItem.grouptype -eq -2147483646)
           {
            $UserType="SG Global"
           }
          elseif ($ADItem.grouptype -eq -2147483644)
           {
            $UserType="SG Local"
           }
         }
        $DisplayName="$($ADItem.displayname)"
        if ("$DisplayName" -eq "")
         {
          $DisplayName="$($ADItem.cn)"
         }
          $TblUserInfoTableResultMembers.Rows.Add("$($Result.samaccountname)",$DomainName,"$($ADItem.samaccountname)","$SearchDomain","$DisplayName","$($ADItem.mail)","$($ADItem.employeenumber)","$($SearchManager.displayname)","$UserType","$($ADItem.extensionattribute1)","$($ADItem.physicaldeliveryofficename) $($ADItem.l) $($ADItem.st) $($ADItem.c) $($ADItem.co)","$($ADItem.telephonenumber)","$($ADItem.othertelephone)","$($ADItem.mobile)","$($ADItem.facsimiletelephonenumber)","$($ADItem.otherfacsimiletelephonenumber)","$($ADItem.'msrtcsip-line')","$($ADItem.pager)","$($ADItem.department)","$($ADItem.company)","$($ADItem.description)","$($ADItem.name)","$Item")
         }
        else
         {
          $LastProp=""
          $PropCN=""
          $PropOU=""
          $PropDC=""
          foreach ($ADItem in ("$Item").split(','))
           {
            if ("$ADItem" -like "*\")
             {
              $ADItem=$ADItem.substring(0,$ADItem.length-1)
             }
            if ($ADItem -like "CN=*" -And "$PropCN" -eq "")
             {
              $LastProp=$ADItem.substring(0,2)
              $PropCN=$ADItem.substring(3,$ADItem.length-3)
             }
            elseif ($ADItem -like "OU=*" -And $PropOU -ne "DL" -And ("$PropOU" -eq "" -or @("Distribution Lists","Groups") -contains "$($ADItem.substring(3,$ADItem.length-3))"))
             {
              $LastProp=$ADItem.substring(0,2)
              $PropOU=$ADItem.substring(3,$ADItem.length-3).replace('Distribution Lists','DL').replace('Groups','SG')
             }
            elseif ($ADItem -like "DC=*")
             {
              $LastProp=$ADItem.substring(0,2)
              $PropDC+="$($ADItem.substring(3,$ADItem.length-3))."
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "CN")
             {
              $PropCN+=",$($ADItem)"
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "OU")
             {
              $PropOU+=",$($ADItem)"
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "DC")
             {
              $PropDC+=",$($ADItem)"
             }
           }
          if ("$PropDC" -like "*.")
           {
            $PropDC=$PropDC.substring(0,$PropDC.length-1)
           }
          $TblUserInfoTableResultMembers.Rows.Add("$($Result.samaccountname)",$DomainName,"$PropCN","$PropDC","$PropOU","$Item")
         }
        if ($FoundTabNames -notcontains "Members") {$FoundTabNames+="Members"}
       }
       }
      if (($chkUserInfoSingleReturn.Checked -eq $False -Or $ResultList.count -eq 1) -And $chkUserInfoDirectReports.Checked -eq $True)
       {
      foreach ($Item in ($Result.directreports))
       {
        if ($chkUserInfoGetExtraDetails.Checked)
         {
        $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
        $Searcher.Filter = "(distinguishedName=*)"
        $Searcher.SearchRoot = (New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$($Item)")
        try {
          $ADItem=($Searcher.FindOne()).Properties
         } Catch {
          $ADItem=$null
         }
        $SearchDomain=""
        if ("$($ADItem.distinguishedname)" -ne "")
         {
          foreach ($DomainItem in $ADItem.distinguishedname.split(","))
           {
            if ($DomainItem.split("=")[0] -eq "DC")
             {
              $SearchDomain+="$($DomainItem.split("=")[1])."
             }
           }
          if ($SearchDomain.length -gt 1)
           {
            $SearchDomain=$SearchDomain.substring(0,$SearchDomain.length-1)
           }
         }
        $SearchManager=$null
        if ("$($ADItem.manager)" -ne "")
         {
          $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
          $Searcher.Filter = "(distinguishedName=*)"
          $Searcher.SearchRoot = (New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$($ADItem.manager)")
          try {
            $SearchManager=($Searcher.FindOne()).Properties
           } Catch {
            $SearchManager=$null
           }
         }
        $UserType=((("$($ADItem.objectcategory),CN=").replace("CN=","")).split(","))[0]
        if ("$UserType" -eq "Group")
         {
          if ($ADItem.grouptype -eq 8)
           {
            $UserType="DL"
           }
          elseif ($ADItem.grouptype -eq 4)
           {
            $UserType="Disabled"
           }
          elseif ($ADItem.grouptype -eq -2147483640)
           {
            $UserType="SG Universal"
           }
          elseif ($ADItem.grouptype -eq -2147483646)
           {
            $UserType="SG Global"
           }
          elseif ($ADItem.grouptype -eq -2147483644)
           {
            $UserType="SG Local"
           }
         }
        $DisplayName="$($ADItem.displayname)"
        if ("$DisplayName" -eq "")
         {
          $DisplayName="$($ADItem.cn)"
         }
          $TblUserInfoTableResultDirectReports.Rows.Add("$($Result.samaccountname)",$DomainName,"$($ADItem.samaccountname)","$SearchDomain","$DisplayName","$($ADItem.mail)","$($ADItem.employeenumber)","$($SearchManager.displayname)","$UserType","$($ADItem.extensionattribute1)","$($ADItem.physicaldeliveryofficename) $($ADItem.l) $($ADItem.st) $($ADItem.c) $($ADItem.co)","$($ADItem.telephonenumber)","$($ADItem.othertelephone)","$($ADItem.mobile)","$($ADItem.facsimiletelephonenumber)","$($ADItem.otherfacsimiletelephonenumber)","$($ADItem.'msrtcsip-line')","$($ADItem.pager)","$($ADItem.department)","$($ADItem.company)","$($ADItem.description)","$($ADItem.name)","$Item")
         }
        else
         {
          $LastProp=""
          $PropCN=""
          $PropOU=""
          $PropDC=""
          foreach ($ADItem in ("$Item").split(','))
           {
            if ("$ADItem" -like "*\")
             {
              $ADItem=$ADItem.substring(0,$ADItem.length-1)
             }
            if ($ADItem -like "CN=*" -And "$PropCN" -eq "")
             {
              $LastProp=$ADItem.substring(0,2)
              $PropCN=$ADItem.substring(3,$ADItem.length-3)
             }
            elseif ($ADItem -like "OU=*" -And $PropOU -ne "DL" -And ("$PropOU" -eq "" -or @("Distribution Lists","Groups") -contains "$($ADItem.substring(3,$ADItem.length-3))"))
             {
              $LastProp=$ADItem.substring(0,2)
              $PropOU=$ADItem.substring(3,$ADItem.length-3).replace('Distribution Lists','DL').replace('Groups','SG')
             }
            elseif ($ADItem -like "DC=*")
             {
              $LastProp=$ADItem.substring(0,2)
              $PropDC+="$($ADItem.substring(3,$ADItem.length-3))."
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "CN")
             {
              $PropCN+=",$($ADItem)"
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "OU")
             {
              $PropOU+=",$($ADItem)"
             }
            elseif ($ADItem -notlike "*=*" -And $LastProp -eq "DC")
             {
              $PropDC+=",$($ADItem)"
             }
           }
          if ("$PropDC" -like "*.")
           {
            $PropDC=$PropDC.substring(0,$PropDC.length-1)
           }
          $TblUserInfoTableResultDirectReports.Rows.Add("$($Result.samaccountname)",$DomainName,"$PropCN","$PropDC","$PropOU","$Item")
         }
        if ($FoundTabNames -notcontains "DirectReports") {$FoundTabNames+="DirectReports"}
       }
       }
      if ($chkUserInfoProperties.Checked -eq $True)
       {
      foreach ($Item in ($Result.PropertyNames))
       {
        if ("$Item" -eq "objectsid")
         {
          $PropValue=(New-Object System.Security.Principal.SecurityIdentifier($Result."$Item"[0],0)).value
         }
        elseif ("$Item" -like "*guid*")
         {
          $PropValue=New-Object Guid @(,$Result."$Item"[0])
         }
        else
         {
          $PropValue=$Result."$Item"
         }
        $TblUserInfoTableResultProperties.Rows.Add("$($Result.samaccountname)",$DomainName,"$ADQueryType",$Item,[string]$PropValue)
        if ($FoundTabNames -notcontains "Properties") {$FoundTabNames+="Properties"}
       }
      $FoundUserFlags=$False
      foreach ($Item in $UserInfo.Properties.Keys)
       {
        if ("$Item" -eq "objectSid")
         {
          $PropValue=(New-Object System.Security.Principal.SecurityIdentifier($UserInfo."$Item"[0],0)).value
         }
        else
         {
          $PropValue=$UserInfo."$Item"
          if ("$Item" -eq "UserFlags")
           {
            $FoundUserFlags=$True
           }
         }
        $TblUserInfoTableResultProperties.Rows.Add("$($Result.samaccountname)",$DomainName,"WinNT",$Item,[string]$PropValue)
        if ($FoundTabNames -notcontains "Properties") {$FoundTabNames+="Properties"}
       }
       if ($FoundUserFlags)
        {
         Foreach ($Flag in $UserFlagsList)
          {
              if ($UserInfo.UserFlags[0] -band $Flag.Value)
               {
                $FlagValue=$True
               }
              else
               {
                $FlagValue=$False
               }
            $TblUserInfoTableResultProperties.Rows.Add("$($Result.samaccountname)",$DomainName,"UserFlags",$Flag.Name,$FlagValue)
          }
        }
       }
     }
############################
### Done checking AD info
############################
   }
  elseif ("$DomainName" -eq "") #Local Computer
   {
############################
### If not found in AD and no domain specified, check WinNT only
############################
      $GetTheseItems=@()
      if ($chkUserInfoComputerUsers.Checked) {$GetTheseItems+="User"}
      if ($chkUserInfoComputerGroups.Checked) {$GetTheseItems+="Group"}
      if ($chkUserInfoComputerServices.Checked) {$GetTheseItems+="Service"}
      if ($GetTheseItems.count -eq 0 -And $chkUserInfoComputerShares.Checked -eq $False)
       {
        $UserInfo=$null
       }
      else
       {
        Try {
          $UserInfo=([ADSI]("WinNT://$SaveLookupName"))
         } Catch {$UserInfo=$null;$GetTheseItems=@()}
       }
      if ("$($UserInfo.SchemaClassName)" -eq "Computer")
       {
       $DisplayName="$($Result.displayname)"
        if ("$DisplayName" -eq "")
         {
          $DisplayName="$($Result.cn)"
         }
        $DomainName="$($UserInfo.Parent.Replace('WinNT://',''))"
        $TblUserInfoTableResultComputer.Rows.Add("$($UserInfo.Name)",$DomainName,"$($UserInfo.Name)","","","","","","","","","","")#,"ExampleColumnComputer"
        if ($FoundTabNames -notcontains "Computer") {$FoundTabNames+="Computer"}
        if ($GetTheseItems.count -gt 0)
         {
          foreach ($Item in ($UserInfo.Children | where {$GetTheseItems -Contains $_.SchemaClassName}))
           {
            if ($Item.SchemaClassName -eq "User")
             {
              $MaxDaysToExpire=([int]"$($Item.MaxPasswordAge)") / (60 * 60 * 24)
              $PwdDaysToExpire=[int]((([int]"$($Item.MaxPasswordAge)")-([int]"$($Item.PasswordAge)")) / (60 * 60 * 24))
              $PasswordExpires=(get-date).AddSeconds((([int]"$($Item.MaxPasswordAge)")-([int]"$($Item.PasswordAge)")))
              if ($Item.UserFlags[0] -band 0x10000)#Never Expires
               {
                $PwdNeverExpires=$True
               }
              else
               {
                $PwdNeverExpires=$False
               }
              if ($Item.UserFlags[0] -band 0x40)#Cannot Change
               {
                $PwdCannotChange=$True
               }
              else
               {
                $PwdCannotChange=$False
               }
              if ($Item.UserFlags[0] -band 0x10)#Locked
               {
                $AccountLocked=$True
               }
              else
               {
                $AccountLocked=$False
               }
              if ($Item.UserFlags[0] -band 0x2)#Disabled
               {
                $AccountDisabled=$True
               }
              else
               {
                $AccountDisabled=$False
               }
              if ($Item.UserFlags[0] -band 0x800000)#Expired
               {
                $PwdExpired=$True
               }
              else
               {
                $PwdExpired=$False
               }
              $TblUserInfoTableResultComputerUsers.Rows.Add("$DomainName","$($UserInfo.Name)\$($Item.Name)","$($Item.FullName)","$((New-Object System.Security.Principal.SecurityIdentifier($Item.objectSid[0],0)).value)","$($Item.GUID)","$PasswordExpires","$PwdDaysToExpire","$MaxDaysToExpire","$($Item.Path)","$($Item.BadPasswordAttempts)",$PwdNeverExpires,$PwdCannotChange,$AccountLocked,$AccountDisabled,$PwdExpired,"$($Item.UserFlags)","$($Item.Parent)")
              if ($FoundTabNames -notcontains "LocalUsers") {$FoundTabNames+="LocalUsers"}
             }
            elseif ($Item.SchemaClassName -eq "Group")
             {
              $TblUserInfoTableResultComputerGroups.Rows.Add("$DomainName","$($UserInfo.Name)\$($Item.Name)","$((New-Object System.Security.Principal.SecurityIdentifier($Item.objectSid[0],0)).value)","$($Item.GUID)","$($Item.Path)","$($Item.Parent)","$($Item.groupType)","$($Item.Description)")
              if ($FoundTabNames -notcontains "LocalGroups") {$FoundTabNames+="LocalGroups"}
             }
            elseif ($Item.SchemaClassName -eq "Service")
             {
              $TblUserInfoTableResultComputerServices.Rows.Add("$DomainName","$($UserInfo.Name)","$($Item.Name)","$($Item.DisplayName)","$($Item.ServiceAccountName)","$($Item.ServiceType)","$($Item.StartType)","$($Item.ErrorControl)","$($Item.Path)","$($Item.GUID)")
              if ($FoundTabNames -notcontains "Services") {$FoundTabNames+="Services"}
             }
           }
         }
        if ($chkUserInfoComputerShares.Checked)
         {
          $UserInfo=([ADSI]("WinNT://$($UserInfo.Name)/lanmanserver"))
          $GetTheseItems=@()
          $GetTheseItems+="FileShare"
          foreach ($Item in ($UserInfo.Children |where {$GetTheseItems -Contains $_.SchemaClassName}))
           {
            if ($Item.SchemaClassName -eq "FileShare")
             {
              $TblUserInfoTableResultComputerShares.Rows.Add("$DomainName","$($UserInfo.Name)","$($Item.Name)","$($Item.Path)","$($Item.CurrentUserCount)","$($Item.Description)","$($Item.GUID)","$($Item.HostComputer)","$($Item.Parent)")
              if ($FoundTabNames -notcontains "Shares") {$FoundTabNames+="Shares"}
             }
           }
         }
############################
### Properties - Very little for Local Computer
############################
      if ($chkUserInfoProperties.Checked -eq $True)
       {
      $FoundUserFlags=$False
      foreach ($Item in $UserInfo.Properties.Keys)
       {
        if ("$Item" -eq "objectSid")
         {
          $PropValue=(New-Object System.Security.Principal.SecurityIdentifier($UserInfo."$Item"[0],0)).value
         }
        elseif ("$Item" -eq "groupType")
         {
          if ($UserInfo."$Item" -eq 8)
           {
            $PropValue="SG Universal"
           }
          elseif ($UserInfo."$Item" -eq 2)
           {
            $PropValue="SG Global"
           }
          elseif ($UserInfo."$Item" -eq 4)
           {
            $PropValue="SG Local"
           }
          else
           {
            $PropValue="SG"
           }
         }
        else
         {
          $PropValue=$UserInfo."$Item"
         }
        $TblUserInfoTableResultProperties.Rows.Add($LookupName,$DomainName,"WinNT",$Item,[string]$PropValue)
        if ($FoundTabNames -notcontains "Properties") {$FoundTabNames+="Properties"}
        if ("$Item" -eq "UserFlags")
         {
          $FoundUserFlags=$True
         }
       }
####################
### UserFlags - Unlikely to be trigged on local computer
####################
       if ($FoundUserFlags)
        {
         Foreach ($Flag in $UserFlagsList)
          {
              if ($UserInfo.UserFlags[0] -band $Flag.Value)
               {
                $FlagValue=$True
               }
              else
               {
                $FlagValue=$False
               }
            $TblUserInfoTableResultProperties.Rows.Add("$($UserInfo.Name)",$DomainName,"UserFlags",$Flag.Name,$FlagValue)
          }
        }
### UserFlags Done
####################
       }
       }
      else
       {
        if ($chkUserInfoDebug.Checked) {write-host "Nothing Found for $SaveLookupName"}
        $TblUserInfoTableResultStatus.Rows.Add("$SaveLookupName","$(get-date)","Not Found")
        if ($FoundTabNames -notcontains "Status") {$FoundTabNames+="Status"}
       }
   }
  else
   {
############################
### If not found in AD and if domain specified, check WinNT with domain - for Groups and Users
############################
    $UserInfo=([ADSI]("WinNT://$DomainName/$LookupName"))
    if ($UserInfo.Properties.count -gt 0)
     {
      Try {$UserType=$UserInfo.SchemaClassName} Catch {$UserType=""}
      Try {$GroupType=$UserInfo.groupType} Catch {$GroupType=""}
      if ("$UserType" -eq "Group")
       {
        if ("$GrouipType" -eq "8")
         {
          $GroupType="SG Universal"
         }
        elseif ("$GroupType" -eq "2")
         {
          $GroupType="SG Global"
         }
        elseif ("$GroupType" -eq "4")
         {
          $GroupType="SG Local"
         }
        else
         {
          $GroupType="Group"
         }
       }
      if ("$UserType" -eq "User")
       {
        $DisplayName="$($UserInfo.FullName)"
        $PasswordExpires=""
        $PwdDaysToExpire=""
        $MaxDaysToExpire=""
        $TblUserInfoTableResultPerson.Rows.Add("$LookupName",$DomainName,"$DisplayName","","","","$UserType","","","","","","","","","","","","","","","$($UserInfo.description)","$PasswordExpires","$PwdDaysToExpire","$MaxDaysToExpire")#,"websitelink"
        if ($FoundTabNames -notcontains "User") {$FoundTabNames+="User"}
       }
      elseif ("$UserType" -eq "Group")
       {
        $TblUserInfoTableResultGroup.Rows.Add("$LookupName",$DomainName,"","","$GroupType","$($UserInfo.description)","$($UserInfo.Name)","WinNT://$DomainName/$LookupName")
        if ($FoundTabNames -notcontains "Group") {$FoundTabNames+="Group"}
       }
      elseif ("$UserType" -eq "Computer")
       {
        $TblUserInfoTableResultComputer.Rows.Add("$LookupName",$DomainName,"$($UserInfo.name)","$($UserInfo.Parent)","","","","","","","","$UserType","WinNT://$DomainName/$LookupName")#,"ExampleColumnComputer"
        if ($FoundTabNames -notcontains "Computer") {$FoundTabNames+="Computer"}
       }
      Try {
        $Members=$UserInfo.psbase.invoke("Members")
       } Catch {$Members=$null}
      foreach ($Item in $Members)
       {
        if ("$SaveLookupName" -ne "")
         {
          if ($cbxUserInfoLookUp.Items -notcontains "$SaveLookupName")
           {
            [void] $cbxUserInfoLookUp.Items.Add("$SaveLookupName")
           }
         }
        $MemberPath=$Item.GetType().InvokeMember("Adspath", "GetProperty", $null, $Item, $null)
        $LastProp=""
        $PropCN=("$MemberPath").split('/')[4]
        if ("$PropCN" -eq "")
         {
          $PropCN=("$MemberPath").split('/')[3]
          $PropDC=("$MemberPath").split('/')[2]
          $PropOU=""
         }
        else
         {
          $PropDC=("$MemberPath").split('/')[3]
          $PropOU=("$MemberPath").split('/')[2]
         }
        $TblUserInfoTableResultMembers.Rows.Add("$LookupName",$DomainName,"$PropCN","$PropDC","$PropOU","$MemberPath")
        if ($FoundTabNames -notcontains "Members") {$FoundTabNames+="Members"}
       }
      if ($chkUserInfoProperties.Checked -eq $True)
       {
        $FoundUserFlags=$False
        foreach ($Item in $UserInfo.Properties.Keys)
         {
          if ("$Item" -eq "objectSid")
           {
            $PropValue=(New-Object System.Security.Principal.SecurityIdentifier($UserInfo."$Item"[0],0)).value
           }
          elseif ("$Item" -eq "groupType")
           {
            if ($UserInfo."$Item" -eq 8)
             {
              $PropValue="SG Universal"
             }
            elseif ($UserInfo."$Item" -eq 2)
             {
              $PropValue="SG Global"
             }
            elseif ($UserInfo."$Item" -eq 4)
             {
              $PropValue="SG Local"
             }
            else
             {
              $PropValue="SG"
             }
           }
          else
           {
            $PropValue=$UserInfo."$Item"
           }
          $TblUserInfoTableResultProperties.Rows.Add($LookupName,$DomainName,"WinNT",$Item,[string]$PropValue)
          if ($FoundTabNames -notcontains "Properties") {$FoundTabNames+="Properties"}
          if ("$Item" -eq "UserFlags")
           {
            $FoundUserFlags=$True
           }
         }
####################
### UserFlags Start
####################
        if ($FoundUserFlags)
         {
          Foreach ($Flag in $UserFlagsList)
           {
            if ($UserInfo.UserFlags[0] -band $Flag.Value)
             {
              $FlagValue=$True
             }
            else
             {
              $FlagValue=$False
             }
            $TblUserInfoTableResultProperties.Rows.Add("$($UserInfo.Name)",$DomainName,"UserFlags",$Flag.Name,$FlagValue)
           }
         }
####################
### UserFlags Done
####################
       }
     }
    else
     {
      if ($chkUserInfoDebug.Checked) {write-host "Nothing Found for $DomainName\$LookupName"}
      $TblUserInfoTableResultStatus.Rows.Add("$SaveLookupName","$(get-date)","Not Found")
      if ($FoundTabNames -notcontains "Status") {$FoundTabNames+="Status"}
     }
   }
 }
############################
### Done checking properties
############################
############################
### Setting up tabs. TC=Tab Count
############################
 if ($FoundMemberOf)
  {
   $TCStart++
  }
 for ($TC=0;$TC -lt $global:UserInfoTabs.Count; $TC++)
  {
   $global:UserInfoGrids[$TC].DataSource = $null
  }
 for ($TC=$tab1.controls.Count;$TC -ge 0; $TC--)
  {
   $tab1.controls.Remove($global:UserInfoTabs[$TC])
  }

############################
### Setup Result Tabs to Display
############################
$SubTabNames=@()
$SubTabNames+="Status"
$SubTabNames+="User"
$SubTabNames+="Group"
$SubTabNames+="Computer"
$SubTabNames+="Other"
$SubTabNames+="Properties"
$SubTabNames+="MemberOf"
$SubTabNames+="ManagedObjects"
$SubTabNames+="Members"
$SubTabNames+="LocalMembers"
$SubTabNames+="ManagedBy"
$SubTabNames+="DirectReports"
$SubTabNames+="LocalUsers"
$SubTabNames+="LocalGroups"
$SubTabNames+="Services"
$SubTabNames+="Shares"

   $TCStart=0
   $TC=0
   foreach ($SubTabName in ($SubTabNames | where {$FoundTabNames -contains $_}))
    {
     if ($global:UserInfoTabs.count -le $TC)
      {
       $global:UserInfoTabs+= new-object System.Windows.Forms.tabpage  
      }
     $global:UserInfoTabs[$TC].Text     = "$SubTabName"
     $global:UserInfoTabs[$TC].Size     = New-object System.Drawing.Size(950, 440)#950
     $global:UserInfoTabs[$TC].TabIndex = $tab1.TabCount
     $tab1.controls.add($global:UserInfoTabs[$TC])
     if ($global:UserInfoGrids.count -gt $TC)
      {
       $global:UserInfoTabs[$TC].Controls.Add($global:UserInfoGrids[$TC])
      }
     elseif ($global:UserInfoGrids.count -le $TC)
      {
       $global:UserInfoGrids+=new-object System.windows.forms.DataGridView
       $global:UserInfoGrids[$TC].Location = new-object System.Drawing.Size(0,0)
       $global:UserInfoGrids[$TC].size = new-object System.Drawing.Size(($tab.Width-16),($tab.Height-$tab1.Top-52-$global:UserInfoGrids[$TC].Top))#974,415
       $global:UserInfoGrids[$TC].DataBindings.DefaultDataSourceUpdateMode = 0
       $global:UserInfoGrids[$TC].AutoSizeColumnsMode = "AllCells"
       $global:UserInfoGrids[$TC].Add_CellDoubleClick({UserInfoResult_DClick $tab1.SelectedIndex})
       #$global:UserInfoGrids[$TC].visible = $True
       #$global:UserInfoGrids[$TC].DataBindings.DefaultDataSourceUpdateMode = 0
       #$global:UserInfoGrids[$TC].ScrollBars="Both"
       $global:UserInfoGrids[$TC].AutoGenerateColumns = $True
       $global:UserInfoGrids[$TC].ReadOnly = $True
       $global:UserInfoGrids[$TC].AllowUserToDeleteRows = $False
       #$global:UserInfoGrids[$TC].RowHeadersVisible = $True
       $global:UserInfoGrids[$TC].AllowUserToAddRows = $False
       $global:UserInfoGrids[$TC].AllowUserToOrderColumns = $True
       $global:UserInfoTabs[$TC].Controls.Add($global:UserInfoGrids[$TC])
      }
     if ($SubTabName -eq "User")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultPerson
        $tempCounters+=" $($TblUserInfoTableResultPerson.rows.count) Users"
      }
     elseif ($SubTabName -eq "Group")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultGroup
       $tempCounters+=" $($TblUserInfoTableResultGroup.rows.count) Groups"
      }
     elseif ($SubTabName -eq "Computer")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultComputer
       $tempCounters+=" $($TblUserInfoTableResultComputer.rows.count) Computers"
      }
     elseif ($SubTabName -eq "Other")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultOther
       $tempCounters+=" $($TblUserInfoTableResultOther.rows.count) Others"
      }
     elseif ($SubTabName -eq "Properties")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultProperties
       $tempCounters+=",$($TblUserInfoTableResultProperties.rows.count) Prop"
      }
     elseif ($SubTabName -eq "Status")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultStatus
       $tempCounters+=" $($TblUserInfoTableResultStatus.rows.count) Status"
      }
     elseif ($SubTabName -eq "MemberOf")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultMemberOf
       $tempCounters+=",$($TblUserInfoTableResultMemberOf.rows.count) MemOf"
      }
     elseif ($SubTabName -eq "ManagedObjects")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultManagedObjects
       $tempCounters+=",$($TblUserInfoTableResultManagedObjects.rows.count) MemObj"
      }
     elseif ($SubTabName -eq "LocalUsers")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultComputerUsers
       $tempCounters+=",$($TblUserInfoTableResultComputerUsers.rows.count) Usr"
      }
     elseif ($SubTabName -eq "LocalGroups")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultComputerGroups
       $tempCounters+=",$($TblUserInfoTableResultComputerGroups.rows.count) Grp"
      }
     elseif ($SubTabName -eq "Services")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultComputerServices
       $tempCounters+=",$($TblUserInfoTableResultComputerServices.rows.count) Svc"
      }
     elseif ($SubTabName -eq "Shares")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultComputerShares
       $tempCounters+=",$($TblUserInfoTableResultComputerShares.rows.count) Shr"
      }
     elseif ($SubTabName -eq "LocalMembers")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultComputerGroupMembers
       $tempCounters+=",$($TblUserInfoTableResultComputerGroupMembers.rows.count) GrpMem"
      }
     elseif ($SubTabName -eq "Members")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultMembers
       $tempCounters+=",$($TblUserInfoTableResultMembers.rows.count) GrpMem"
      }
     elseif ($SubTabName -eq "ManagedBy")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultManagedBy
       $tempCounters+=",$($TblUserInfoTableResultManagedBy.rows.count) MngdBy"
      }
     elseif ($SubTabName -eq "DirectReports")
      {
       $global:UserInfoGrids[$TC].DataSource = $TblUserInfoTableResultDirectReports
       $tempCounters+=",$($TblUserInfoTableResultDirectReports.rows.count) DirRep"
      }
     $TC++
    }
 $tab1.SelectedIndex=0
 If (("$($tbxUserInfoFilter.Text)$($tbxUserInfoExclude.Text)").Trim() -ne "")# -Or ($global:UserInfoLastFiltered)
  {
   $tempCounters+=",FILTERING"
   ClickUserInfoFilterGo
  }
 StatusUpdate $tab.SelectedIndex "($tempCounters) ($(get-date))" $null $null
 $btnUserInfoLookUp.Enabled=$True
}

Function ChangedSelectUserInfoLookup($SearchProperty="")
{
 if ("$($cbxUserInfoLookUp.SelectedItem)" -ne "")
  {
   $cbxUserInfoLookUp.Text="$($cbxUserInfoLookUp.SelectedItem)"
  }
 ClickUserInfoLookUp $SearchProperty
}

Function UserInfoResult_DClick($TC=0)
{
 if ($chkUserInfoDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 $CellHeader="$($global:UserInfoGrids[$TC].CurrentCell.OwningColumn.HeaderText)"
 $CellValue = [String]($global:UserInfoGrids[$TC].Item($global:UserInfoGrids[$TC].CurrentCell.ColumnIndex,$global:UserInfoGrids[$TC].CurrentCell.RowIndex)).Value
 $FilterName=""
 if ("$CellHeader" -eq "Alias")
  {
   $FilterName="sAMAccountName"
  }
 elseif ("$CellHeader" -eq "EmployeeId")
  {
   $FilterName="employeenumber"
  }
 elseif ("$CellHeader" -eq "DisplayName" -or "$CellHeader" -eq "FullName" -or "$CellHeader" -eq "Manager")
  {
   $FilterName="displayname"# cn name
  }
 elseif ("$CellHeader" -eq "Email")
  {
   $FilterName="mail"
  }
 elseif ("$CellHeader" -eq "LocalUser" -Or "$CellHeader" -eq "LocalGroup")
  {
   $FilterName="Local"
  }
 elseif ("$CellHeader" -eq "CN")
  {
   $FilterName="cn"
  }
 if ("$FilterName" -ne "")
  {
   $cbxUserInfoLookUp.Text="$CellValue"
   if ($cbxUserInfoLookUp.Items -notcontains "$CellValue")
    {
     [void] $cbxUserInfoLookUp.Items.Add("$CellValue")
    }
   $cbxUserInfoLookUp.SelectedItem="$CellValue"
   ChangedSelectUserInfoLookup "$FilterName"
  }
 else
  {
   $OnTopWas = $Form.topmost
   $Form.topmost = $false
   if ($chkUserInfoDebug.Checked) {write-host $CellValue}
   if ($False)
    {
     Start-Process -FilePath "C:\Program Files\Internet Explorer\iexplore.exe" -wait -ArgumentList "$CellValue"
    }
   elseif ("$CellValue" -like "*<ShowPlanXML *</ShowPlanXML>*")
    {
     $CellValue=$CellValue.replace("><",">`r`n<")
     OpenTextBox $CellValue
    }
   else
    {
     OpenTextBox $CellValue
    }
   $Form.topmost = $OnTopWas
  }
}

Function ClickAlwaysOnTop
{
 if ($chkUserInfoDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 $form.topmost=$chkUserInfoAlwaysOnTop.Checked
 if ($chkUserInfoAlwaysOnTop.Checked)
  {
   StatusUpdate $tab.SelectedIndex $null "Checked Always On Top" $null
  }
 else
  {
   StatusUpdate $tab.SelectedIndex $null "Unchecked Always On Top" $null
  }
}

#################### UserInfo Tab Functions
###################################################################

Function FormSizeChanged
{
 if ($Form.Width -gt 10)
  {
     $tab.Width=$Form.Width-20
  }
 if ($Form.Height -gt 100)
  {
   $tab.Height=$Form.Height-65
   if ($tab.Height -gt (61+$tab1.Top))
    {
     $tab1.Height=($tab.Height-$tab1.Top-26)
    }
  }
 if ($Form.Width -gt 10)
  {
   if ($tab.Width -gt 20)
    {
     $tab1.Width=$tab.Width-8
    }
   for ($TC=0;$TC -lt $global:UserInfoGrids.Count; $TC++)
    {
     $global:UserInfoGrids[$TC].Width=$Form.Width-36
    }
  }
 if ($Form.Height -gt 40)
  {
   if ($Form.Height -gt 100)
    {
     for ($TC=0;$TC -lt $global:UserInfoGrids.Count; $TC++)
      {
       $global:UserInfoGrids[$TC].Height=$Form.Height-235-$global:UserInfoGrids[$TC].Top
      }
    }
  }
}

###############################################################################
### ### End Functions ### ###
###############################################################################

##############################################################################################################################################################
##############################################################################################################################################################
##############################################################################################################################################################

###############################################################################
### ### Create GUI ### ###
###############################################################################
$form = new-object System.Windows.Forms.form

#####################################################################
### Create Tabs
#####################################################################
$tab = new-object System.Windows.Forms.tabcontrol
$tab.Location = New-object System.Drawing.Point(1, 1)
$tab.Size = New-object System.Drawing.Size(990, 570)
$tab.SelectedIndex = 0
$tab.TabIndex = 0
#$tab.Add_SelectedIndexChanged({ClickChangeTab})

$tab1 = new-object System.Windows.Forms.tabcontrol
$tab1.Location = New-object System.Drawing.Point(0, 119)#119
$tab1.Size = New-object System.Drawing.Size(($tab.Width-8), ($tab.Height-$tab1.Top-26))
$tab1.SelectedIndex = 0
$tab1.TabIndex = 0
#$tab1.Add_SelectedIndexChanged({ClickChangeTab})

#####################################################################
### Tab Drawing: UserInfo
#####################################################################

##### Tabs:
$tabUserInfo   = new-object System.Windows.Forms.tabpage  
##### Add Tab:
$tabUserInfo.Text     = "Lookup"
$tabUserInfo.Size     = New-object System.Drawing.Size(950, 450)
$tabUserInfo.TabIndex = $tab.TabCount
$tab.controls.add($tabUserInfo)

$lblUserInfoLookUp           = New-Object System.Windows.Forms.Label
$lblUserInfoLookUp.Location  = New-Object System.Drawing.Size(8,2)
$lblUserInfoLookUp.Size      = New-Object System.Drawing.Size(60,15)
$lblUserInfoLookUp.Text      = "Lookup:"
$tabUserInfo.Controls.Add($lblUserInfoLookUp)


$cbxUserInfoLookUp = New-Object System.Windows.Forms.ComboBox
 $cbxUserInfoLookUp.Location = New-Object System.Drawing.Size(70,0)
 $cbxUserInfoLookUp.Size = New-Object System.Drawing.Size(300,10)
 $cbxUserInfoLookUp.Height = 30
$cbxUserInfoLookUp.Sorted = $True
$cbxUserInfoLookUp.Text="$CurrentUser"
$cbxUserInfoLookUp.Enabled=$True
$cbxUserInfoLookUp.Add_SelectedValueChanged({ChangedSelectUserInfoLookup})
$cbxUserInfoLookUp.Add_MouseHover({$ToolTip.SetToolTip($this,"String to search. User, group, or computer. With or without domain. Ex: Domain\user")})
#$cbxUserInfoLookUp.Add_KeyPress({
#if($_.KeyChar -eq 13)
#$_.SuppressKeyPress=$True
#$_.Handled=$True
$cbxUserInfoLookUp.Add_KeyUp({
    if ($_.KeyCode -eq "Enter")
     {
      ClickUserInfoLookUp
     }
})
$tabUserInfo.Controls.Add($cbxUserInfoLookUp)

[void] $cbxUserInfoLookUp.Items.Add("$CurrentUser")
[void] $cbxUserInfoLookUp.Items.Add("$CurrentComputer")
if ("$File" -ne "")
 {
  if (test-path $File)
   {
    foreach ($line in (gc $File))
     {
      [void] $cbxUserInfoLookUp.Items.Add("$line")
     }
   }
 }

$chkUserInfoFullName          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoFullName.Location = New-Object System.Drawing.Size(8,20)
$chkUserInfoFullName.size     = new-object System.Drawing.Size(92,20)
$chkUserInfoFullName.Text     = "FullName"
$chkUserInfoFullName.Checked  = $True
$chkUserInfoFullName.Add_MouseHover({$ToolTip.SetToolTip($this,"Searches cn, displayname, and name in AD for string")})
$tabUserInfo.Controls.Add($chkUserInfoFullName)

$chkUserInfoMail          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoMail.Location = New-Object System.Drawing.Size(100,20)
$chkUserInfoMail.size     = new-object System.Drawing.Size(100,20)
$chkUserInfoMail.Text     = "Mail"
$chkUserInfoMail.Checked  = $True
$chkUserInfoMail.Add_MouseHover({$ToolTip.SetToolTip($this,"Searches mail, userprincipalname, and mailnickname in AD for string")})
$tabUserInfo.Controls.Add($chkUserInfoMail)

$chkUserInfoEmployeeID          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoEmployeeID.Location = New-Object System.Drawing.Size(200,20)
$chkUserInfoEmployeeID.size     = new-object System.Drawing.Size(100,20)
$chkUserInfoEmployeeID.Text     = "EmployeeId"
$chkUserInfoEmployeeID.Checked  = $True
$chkUserInfoEmployeeID.Add_MouseHover({$ToolTip.SetToolTip($this,"Searches employeenumber and employeeid in AD for string")})
$tabUserInfo.Controls.Add($chkUserInfoEmployeeID)

$chkUserInfoLastName          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoLastName.Location = New-Object System.Drawing.Size(8,40)
$chkUserInfoLastName.size     = new-object System.Drawing.Size(92,20)
$chkUserInfoLastName.Text     = "LastName"
$chkUserInfoLastName.Checked  = $True
$chkUserInfoLastName.Add_MouseHover({$ToolTip.SetToolTip($this,"Searches sn in AD for string")})
$tabUserInfo.Controls.Add($chkUserInfoLastName)

$chkUserInfoFirstName          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoFirstName.Location = New-Object System.Drawing.Size(100,40)
$chkUserInfoFirstName.size     = new-object System.Drawing.Size(100,20)
$chkUserInfoFirstName.Text     = "FirstName"
$chkUserInfoFirstName.Checked  = $True
$chkUserInfoFirstName.Add_MouseHover({$ToolTip.SetToolTip($this,"Searches givenname in AD for string")})
$tabUserInfo.Controls.Add($chkUserInfoFirstName)

$chkUserInfoAlias          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoAlias.Location = New-Object System.Drawing.Size(200,40)
$chkUserInfoAlias.size     = new-object System.Drawing.Size(100,20)
$chkUserInfoAlias.Text     = "Alias"
$chkUserInfoAlias.Checked  = $True
$chkUserInfoAlias.Add_MouseHover({$ToolTip.SetToolTip($this,"Searches sAMAccountName in AD for string")})
$tabUserInfo.Controls.Add($chkUserInfoAlias)

$btnUserInfoLookUp          = new-object System.Windows.Forms.Button  
$btnUserInfoLookUp.Location = new-object System.Drawing.Size(370,0)
$btnUserInfoLookUp.Size     = new-object System.Drawing.Size(120,23)
$btnUserInfoLookUp.Text     = "Lookup"
$btnUserInfoLookUp.Enabled  = $True
$btnUserInfoLookUp.Add_Click({ClickUserInfoLookUp})
$btnUserInfoLookUp.Add_MouseHover({$ToolTip.SetToolTip($this,"Searches AD (GC or LDAP) and/or WinNT for string specified")})
$tabUserInfo.Controls.Add($btnUserInfoLookUp)

$chkUserInfoExactMatch          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoExactMatch.Location = New-Object System.Drawing.Size(492,0)
$chkUserInfoExactMatch.size     = new-object System.Drawing.Size(88,20)
$chkUserInfoExactMatch.Text     = "ExactMatch"
$chkUserInfoExactMatch.Checked  = $True
$chkUserInfoExactMatch.Add_MouseHover({$ToolTip.SetToolTip($this,"If unchecked, puts wild cards around string. Ex: MyUser will be *MyUser*")})
$tabUserInfo.Controls.Add($chkUserInfoExactMatch)

$lblUserInfoFilter           = New-Object System.Windows.Forms.Label
$lblUserInfoFilter.Location  = New-Object System.Drawing.Size(340,43)
$lblUserInfoFilter.Size      = New-Object System.Drawing.Size(50,15)
$lblUserInfoFilter.Text      = "FilterOn:"
$tabUserInfo.Controls.Add($lblUserInfoFilter)

$tbxUserInfoFilter = New-Object System.Windows.Forms.TextBox
 $tbxUserInfoFilter.Location = New-Object System.Drawing.Size(390,40)
 $tbxUserInfoFilter.Size = New-Object System.Drawing.Size(100,10)
 $tbxUserInfoFilter.Height = 30
$tbxUserInfoFilter.Text=""
$tbxUserInfoFilter.Add_MouseHover({$ToolTip.SetToolTip($this,"String to filter on. Only show rows with this string")})
$tabUserInfo.Controls.Add($tbxUserInfoFilter)

$lblUserInfoExclude           = New-Object System.Windows.Forms.Label
$lblUserInfoExclude.Location  = New-Object System.Drawing.Size(340,63)
$lblUserInfoExclude.Size      = New-Object System.Drawing.Size(50,15)
$lblUserInfoExclude.Text      = "Exclude:"
$tabUserInfo.Controls.Add($lblUserInfoExclude)

$tbxUserInfoExclude = New-Object System.Windows.Forms.TextBox
 $tbxUserInfoExclude.Location = New-Object System.Drawing.Size(390,60)
 $tbxUserInfoExclude.Size = New-Object System.Drawing.Size(100,10)
 $tbxUserInfoExclude.Height = 30
$tbxUserInfoExclude.Text=""
$tbxUserInfoExclude.Add_MouseHover({$ToolTip.SetToolTip($this,"String to Exclude. Only show rows without this string")})
$tabUserInfo.Controls.Add($tbxUserInfoExclude)

$lblUserInfoColumns           = New-Object System.Windows.Forms.Label
$lblUserInfoColumns.Location  = New-Object System.Drawing.Size(340,83)
$lblUserInfoColumns.Size      = New-Object System.Drawing.Size(50,15)
$lblUserInfoColumns.Text      = "Columns:"
$tabUserInfo.Controls.Add($lblUserInfoColumns)

$tbxUserInfoColumns = New-Object System.Windows.Forms.TextBox
 $tbxUserInfoColumns.Location = New-Object System.Drawing.Size(390,80)
 $tbxUserInfoColumns.Size = New-Object System.Drawing.Size(100,10)
 $tbxUserInfoColumns.Height = 30
$tbxUserInfoColumns.Text=""
$tbxUserInfoColumns.Add_MouseHover({$ToolTip.SetToolTip($this,"Columns to search for filters. Ex: Alias,Name,Value")})
$tabUserInfo.Controls.Add($tbxUserInfoColumns)

$chkUserInfoFilterCaseSensitive          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoFilterCaseSensitive.Location = New-Object System.Drawing.Size(410,100)
$chkUserInfoFilterCaseSensitive.size     = new-object System.Drawing.Size(80,20)
$chkUserInfoFilterCaseSensitive.Text     = "Case-Sens"
$chkUserInfoFilterCaseSensitive.Checked  = $False
$chkUserInfoFilterCaseSensitive.Add_MouseHover({$ToolTip.SetToolTip($this,"Filter Case-Sensitive")})
$tabUserInfo.Controls.Add($chkUserInfoFilterCaseSensitive)

$chkUserInfoFilterExactMatch          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoFilterExactMatch.Location = New-Object System.Drawing.Size(340,100)
$chkUserInfoFilterExactMatch.size     = new-object System.Drawing.Size(70,20)
$chkUserInfoFilterExactMatch.Text     = "Exact"
$chkUserInfoFilterExactMatch.Checked  = $False
$chkUserInfoFilterExactMatch.Add_MouseHover({$ToolTip.SetToolTip($this,"Filter Exact Match of string. Uncheck puts wildcard around string")})
$tabUserInfo.Controls.Add($chkUserInfoFilterExactMatch)

$btnUserInfoFilterGo          = new-object System.Windows.Forms.Button  
$btnUserInfoFilterGo.Location = new-object System.Drawing.Size(492,40)
$btnUserInfoFilterGo.Size     = new-object System.Drawing.Size(40,20)
$btnUserInfoFilterGo.Text     = "Filter"
$btnUserInfoFilterGo.Enabled  = $True
$btnUserInfoFilterGo.Add_Click({ClickUserInfoFilterGo})
$btnUserInfoFilterGo.Add_MouseHover({$ToolTip.SetToolTip($this,"Filters after Lookup. Blank-out filter strings and click on Filter button to unfilter")})
$tabUserInfo.Controls.Add($btnUserInfoFilterGo)

$chkUserInfoProperties          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoProperties.Location = New-Object System.Drawing.Size(590,0)
$chkUserInfoProperties.size     = new-object System.Drawing.Size(98,20)
$chkUserInfoProperties.Text     = "GetProperties"
$chkUserInfoProperties.Checked  = $True
$chkUserInfoProperties.Add_MouseHover({$ToolTip.SetToolTip($this,"Gets properties (AD, WinNT and/or UserFlags). Can be large on multiple returns")})
$tabUserInfo.Controls.Add($chkUserInfoProperties)

$chkUserInfoMemberOf          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoMemberOf.Location = New-Object System.Drawing.Size(590,20)
$chkUserInfoMemberOf.size     = new-object System.Drawing.Size(120,20)
$chkUserInfoMemberOf.Text     = "MemberOf"
$chkUserInfoMemberOf.Checked  = $True
$chkUserInfoMemberOf.Add_MouseHover({$ToolTip.SetToolTip($this,"Gets members from memberof")})
$tabUserInfo.Controls.Add($chkUserInfoMemberOf)

$chkUserInfoManagedObjects          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoManagedObjects.Location = New-Object System.Drawing.Size(590,40)
$chkUserInfoManagedObjects.size     = new-object System.Drawing.Size(120,20)
$chkUserInfoManagedObjects.Text     = "ManagedObjects"
$chkUserInfoManagedObjects.Checked  = $True
$chkUserInfoManagedObjects.Add_MouseHover({$ToolTip.SetToolTip($this,"Gets members from managedobjects")})
$tabUserInfo.Controls.Add($chkUserInfoManagedObjects)

$chkUserInfoMembers          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoMembers.Location = New-Object System.Drawing.Size(590,60)
$chkUserInfoMembers.size     = new-object System.Drawing.Size(120,20)
$chkUserInfoMembers.Text     = "Members"
$chkUserInfoMembers.Checked  = $True
$chkUserInfoMembers.Add_MouseHover({$ToolTip.SetToolTip($this,"Gets Group members from member. DL, SG Universal, SG Global, and SG Local")})
$tabUserInfo.Controls.Add($chkUserInfoMembers)

$chkUserInfoManagedBy          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoManagedBy.Location = New-Object System.Drawing.Size(590,80)
$chkUserInfoManagedBy.size     = new-object System.Drawing.Size(120,20)
$chkUserInfoManagedBy.Text     = "ManagedBy"
$chkUserInfoManagedBy.Checked  = $True
$chkUserInfoManagedBy.Add_MouseHover({$ToolTip.SetToolTip($this,"Gets members from managedby and msexchcomanagedbylink")})
$tabUserInfo.Controls.Add($chkUserInfoManagedBy)

$chkUserInfoDirectReports          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoDirectReports.Location = New-Object System.Drawing.Size(590,100)
$chkUserInfoDirectReports.size     = new-object System.Drawing.Size(120,20)
$chkUserInfoDirectReports.Text     = "DirectReports"
$chkUserInfoDirectReports.Checked  = $True
$chkUserInfoDirectReports.Add_MouseHover({$ToolTip.SetToolTip($this,"Gets members from directreports")})
$tabUserInfo.Controls.Add($chkUserInfoDirectReports)

$chkUserInfoGetExtraDetails          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoGetExtraDetails.Location = New-Object System.Drawing.Size(720,0)
$chkUserInfoGetExtraDetails.size     = new-object System.Drawing.Size(300,20)
$chkUserInfoGetExtraDetails.Text     = "Get Extra Member Details (slower)"
$chkUserInfoGetExtraDetails.Checked  = $False
$chkUserInfoGetExtraDetails.Add_MouseHover({$ToolTip.SetToolTip($this,"Slow: Queries each member returned for more information from Group, DirectReports, etc...")})
$tabUserInfo.Controls.Add($chkUserInfoGetExtraDetails)

$chkUserInfoSingleReturn          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoSingleReturn.Location = New-Object System.Drawing.Size(720,20)
$chkUserInfoSingleReturn.size     = new-object System.Drawing.Size(220,20)
$chkUserInfoSingleReturn.Text     = "No extra details on multiple returns"
$chkUserInfoSingleReturn.Checked  = $True
$chkUserInfoSingleReturn.Add_MouseHover({$ToolTip.SetToolTip($this,"If above checked, only get member info on single group returns (Group, DirectReports, etc...)")})
$tabUserInfo.Controls.Add($chkUserInfoSingleReturn)

$chkUserInfoComputerUsers          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoComputerUsers.Location = New-Object System.Drawing.Size(720,40)
$chkUserInfoComputerUsers.size     = new-object System.Drawing.Size(220,20)
$chkUserInfoComputerUsers.Text     = "Get Local Computer Users"
$chkUserInfoComputerUsers.Checked  = $True
$chkUserInfoComputerUsers.Add_MouseHover({$ToolTip.SetToolTip($this,"WinNT Query of local users if Computer specified. Must have access to computer")})
$tabUserInfo.Controls.Add($chkUserInfoComputerUsers)

$chkUserInfoComputerGroups          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoComputerGroups.Location = New-Object System.Drawing.Size(720,60)
$chkUserInfoComputerGroups.size     = new-object System.Drawing.Size(220,20)
$chkUserInfoComputerGroups.Text     = "Get Local Computer Groups"
$chkUserInfoComputerGroups.Checked  = $True
$chkUserInfoComputerGroups.Add_MouseHover({$ToolTip.SetToolTip($this,"WinNT Query of local groups if Computer specified. Must have access to computer")})
$tabUserInfo.Controls.Add($chkUserInfoComputerGroups)

$chkUserInfoComputerServices          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoComputerServices.Location = New-Object System.Drawing.Size(720,80)
$chkUserInfoComputerServices.size     = new-object System.Drawing.Size(220,20)
$chkUserInfoComputerServices.Text     = "Get Local Computer Services"
$chkUserInfoComputerServices.Checked  = $True
$chkUserInfoComputerServices.Add_MouseHover({$ToolTip.SetToolTip($this,"WinNT Query of local services if Computer specified. Must have access to computer")})
$tabUserInfo.Controls.Add($chkUserInfoComputerServices)

$chkUserInfoComputerShares          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoComputerShares.Location = New-Object System.Drawing.Size(720,100)
$chkUserInfoComputerShares.size     = new-object System.Drawing.Size(220,20)
$chkUserInfoComputerShares.Text     = "Get Local Computer Shares"
$chkUserInfoComputerShares.Checked  = $True
$chkUserInfoComputerShares.Add_MouseHover({$ToolTip.SetToolTip($this,"WinNT lanmanserver Query of local shares if Computer specified. Must have access to computer")})
$tabUserInfo.Controls.Add($chkUserInfoComputerShares)

$chkUserInfoAlwaysOnTop          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoAlwaysOnTop.Location = New-Object System.Drawing.Size(495,80)
$chkUserInfoAlwaysOnTop.size     = new-object System.Drawing.Size(100,20)
$chkUserInfoAlwaysOnTop.Text     = "AlwaysOnTop"
$chkUserInfoAlwaysOnTop.Checked  = $form.topmost
$chkUserInfoAlwaysOnTop.Add_Click({ClickAlwaysOnTop})
$chkUserInfoAlwaysOnTop.Add_MouseHover({$ToolTip.SetToolTip($this,"puts this in the foreground on top of other applications")})
$tabUserInfo.Controls.Add($chkUserInfoAlwaysOnTop)

$chkUserInfoDebug          = New-Object System.Windows.Forms.CheckBox
$chkUserInfoDebug.Location = New-Object System.Drawing.Size(495,100)
$chkUserInfoDebug.size     = new-object System.Drawing.Size(100,20)
$chkUserInfoDebug.Text     = "Debug"
$chkUserInfoDebug.Checked  = $true
$chkUserInfoDebug.Add_MouseHover({$ToolTip.SetToolTip($this,"shows on command prompt which functions are executed")})
$tabUserInfo.Controls.Add($chkUserInfoDebug)

$tabUserInfo.Controls.Add($tab1)

###############################################################################
###############################################################################
###############################################################################

$global:TabIndexList=@()
for ($iTab=0; $iTab -lt $tab.TabCount; $iTab++)
 {
  $global:TabIndexList += New-Object PSObject -Property @{
    Status=$tab.TabPages[$iTab].text
    Details=""
    Server="$CurrentComputer"
   }
 }

###############################################################################
### Status Bar:
###############################################################################
$StatusBar = new-object System.Windows.Forms.StatusBar
$StatusBar_P1 = new-object System.Windows.Forms.StatusBarPanel
$StatusBar_P2 = new-object System.Windows.Forms.StatusBarPanel
$StatusBar_P3 = new-object System.Windows.Forms.StatusBarPanel
$StatusBar_P1.Text = ""
$StatusBar_P1.BorderStyle = "Sunken"
$StatusBar_P1.AutoSize = "Spring"
$StatusBar_P2.Text = ""
$StatusBar_P2.BorderStyle = "Sunken"
$StatusBar_P2.AutoSize = "Spring"
$StatusBar_P3.Text = "$CurrentComputer"
$StatusBar_P3.BorderStyle = "Sunken"
$StatusBar_P3.width = 150
[void]$StatusBar.Panels.Add($StatusBar_P1)
[void]$StatusBar.Panels.Add($StatusBar_P2)
[void]$StatusBar.Panels.Add($StatusBar_P3)
$form.Controls.Add($StatusBar)
$StatusBar.ShowPanels = $true
#ClickChangeTab

###############################################################################
### Draw the GUI:
###############################################################################
$Form.Controls.Add($tab)
$Form.Text = "AD Lookup Tool - User, Group, and Computer Info - Domain and Local - Written By: John Merager"
$Form.size = new-object System.Drawing.Size(($tab.Width+20), ($tab.Height+65))#1010,635
$Form.autoscroll = $true
$Form.topmost = $false
$chkUserInfoAlwaysOnTop.Checked=$Form.topmost
$Form.MaximizeBox = $False
$Form.Add_SizeChanged({FormSizeChanged})
$Form.Add_Shown({$Form.Activate()})

$Ended = $Form.ShowDialog()

Write-host "$Ended"
If ($Ended -eq "Cancel")
{
    write-host "Form Closed"
}

###############################################################################
### END
###############################################################################