# FindMachineOU.ps1

# Purpose

Interactively locates one or more computers in Active Directory by DNS name or partial name, and displays their distinguished name (OU) and other details. Useful for resolving naming conflicts or verifying machine location in AD.

# Function

  1. Prompts the user to enter a machine name or partial name (via Read-Host).
  2. Searches Active Directory for computers whose DNSHostName matches the input (using Get-ADComputer).
  3. Displays results in a formatted table: DisplayName, Name, DistinguishedName.
  4. Waits for user to press Enter before exiting.
  5. Handles connection to Exchange/AD if required (with fallback logic for session import).

# Usage

./FindMachineOU.ps1

The script is interactive and does not require command-line parameters.

# Inputs

  • User input: Machine name or partial name (prompted at runtime).

# Variables

  • $machineName: Stores the user-provided machine name or partial name.
  • $scriptComplete: Tracks script completion state.

# Command Line Flags

None. All input is provided interactively.

# Outputs

  • Displays a table of matching AD computers, including DisplayName, Name, and DistinguishedName (OU path).
  • If no matches are found, the table will be empty.

# Notes

  • Requires the Active Directory module (Get-ADComputer).
  • Loads Windows Forms assembly for compatibility, but does not use GUI elements.
  • Attempts to connect to Exchange/AD if not already connected (fallback logic included).
  • Useful for troubleshooting machine naming conflicts or verifying AD structure.