Assistant: Let's complete the function and adjust it to resemble the output format you’ve shown. Here's how you can modify the script to include additional properties such as `whenCreated`, `MemberOf`, `lastLogonDate`, `PasswordExpired`, and `userAccountControl`:

```powershell
function Search-User {
    Write-Host "Enter the 'User Management' section and select option 2: Search User"
    $searchQuery = Read-Host -Prompt "Enter username to search (use * for wildcards)"
    
    # Search for users matching the query using wildcards
    $matchedUsers = Get-ADUser -Filter "SamAccountName -like '$searchQuery'" -Properties whenCreated, MemberOf, lastLogonDate, PasswordExpired, userAccountControl, LockedOut -ErrorAction SilentlyContinue
    
    if ($matchedUsers) {
        foreach ($user in $matchedUsers) {
            # Display the user's properties according to the required format
            $output = @{
                Name = $user.SamAccountName
                whenCreated = $user.whenCreated
                DistinguishedName = $user.DistinguishedName
                MemberOf = $user.MemberOf
                lastLogonDate = $user.lastLogonDate
                PasswordExpired = $user.PasswordExpired
                userAccountControl = $user.userAccountControl
            }
            $output | Format-List
            
            # Check if the user account is locked
            if ($user.LockedOut) {
                $unlockChoice = Read-Host -Prompt "The account is locked. Do you want to unlock it? (Y/N)"
                if ($unlockChoice -eq 'Y') {
                    try {
                        Unlock-ADAccount -Identity $user
                        Write-Host "Account unlocked successfully." -ForegroundColor Green
                    } catch {
                        Write-Host "Failed to unlock account: $_" -ForegroundColor Red
                    }
                }
            }
            
            # Ask if the admin wants to delete the account
            $deleteChoice = Read-Host -Prompt "Do you want to
Assistant: delete account: $_" -ForegroundColor Red
                }
            }
        }
   
User: Read-Host : A parameter cannot be found that matches parameter name 'ForegroundColor'.
At C:\Users\Administrator\Desktop\test.ps1:72 char:82
+ ... -Host -Prompt "Do you want todelete account: $_" -ForegroundColor Red
+                                                      ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Read-Host], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.ReadHostCommand
Assistant: It looks like there was a typo in the script. `Read-Host` does not have a `-ForegroundColor` parameter. We should use `Write-Host` for colored output messages. 

Here's the corrected `Search-User` function with improvements and necessary fixes:

```powershell
function Search-User {
    Write-Host "Enter the 'User Management' section and select option 2: Search User"
    $searchQuery = Read-Host -Prompt "Enter username to search (use * for wildcards)"
    
    # Search for users matching the query using wildcards
    $matchedUsers = Get-ADUser -Filter "SamAccountName -like '$searchQuery'" -Properties whenCreated, MemberOf, lastLogonDate, PasswordExpired, userAccountControl, LockedOut -ErrorAction SilentlyContinue
    
    if ($matchedUsers) {
        foreach ($user in $matchedUsers) {
            # Display the user's properties formatted similarly to the given example
            $output = @{
                Name = $user.SamAccountName
                whenCreated = $user.whenCreated
                DistinguishedName = $user.DistinguishedName
                MemberOf = $user.MemberOf
                lastLogonDate = $user.lastLogonDate
                PasswordExpired = $user.PasswordExpired
                userAccountControl = $user.userAccountControl
            }
            $output | Format-List
            
            # Check if the user account is locked
            if ($user.LockedOut) {
                $unlockChoice = Read-Host -Prompt "The account is locked. Do you want to unlock it? (Y/N)"
                if ($unlockChoice -eq 'Y') {
                    try {
                        Unlock-ADAccount -Identity $user
                        Write-Host "Account unlocked successfully." -ForegroundColor Green
                    } catch {
                        Write-Host "Failed to unlock account: $_" -ForegroundColor Red
                    }
                }
            }
            
            # Ask if the admin wants to delete the account
            $deleteChoice = Read-Host -Prompt "Do you want to delete this account? (Y/N)"
            if ($deleteChoice -eq 'Y') {
                try {
                    Remove-ADUser -Identity $user -Confirm:$false
                    Write-Host "Account deleted successfully." -ForegroundColor Green
                } catch {
                    Write-Host "Failed to delete account: $_" -ForegroundColor Red
                }
            }
        }
    } else {
        Write-Host "No users found matching the search criteria." -ForegroundColor Yellow
    }
}
```

### Explanation:
1. **Property Selection**: The function now fetches additional properties (whenCreated, MemberOf, lastLogonDate, PasswordExpired, userAccountControl) needed for the output.
2. **Formatted Output**: The user properties are displayed using a `Format-List` for readability similar to the provided example format.
3. **Color Output**: `Write-Host` with `-ForegroundColor` is used for colored output to convey success or failure messages.
4. **Error Handling**: Attempt to unlock and delete accounts includes error handling to catch and display any issues encountered.

This script should now output the user information as shown in your example and corrects the misuse of parameters, ensuring a smooth run.
User: i want if I input "tom" it can also show up "tommy"
Assistant: To accommodate searching for user accounts where input like "tom" can also return "tommy", you can leverage PowerShell's wildcard capabilities within the filter of `Get-ADUser`. Wildcards allow for pattern matching, which is particularly useful in your scenario for matching parts of strings.

The `-like` operator in PowerShell can be combined with wildcard characters (`*`) to search for user accounts that start with "tom" but may have additional characters following it. To apply this to your script, you can modify the search query to automatically include wildcards around the input:

```powershell
function Search-User {
    Write-Host "Enter the 'User Management' section and select option 2: Search User"
    $searchQuery = Read-Host -Prompt "Enter username to search"
    
    # Adding wildcards around the search query to match similar names
    $wildcardQuery = "*$searchQuery*"
    
    # Search for users matching the query using wildcards
    $matchedUsers = Get-ADUser -Filter "SamAccountName -like '$wildcardQuery'" -Properties whenCreated, MemberOf, lastLogonDate, PasswordExpired, userAccountControl, LockedOut -ErrorAction SilentlyContinue
    
    if ($matchedUsers) {
        foreach ($user in $matchedUsers) {
            # Display the user's properties formatted similarly to the given example
            $output = @{
                Name = $user.sAMAccountName
                whenCreated = $user.whenCreated
                DistinguishedName = $user.DistinguishedName
                MemberOf = $user.MemberOf -join ', '
                lastLogonDate = $user.lastLogonDate
                PasswordExpired = $user.PasswordExpired
                userAccountControl = $user.userAccountControl
                LockedOut = $user.LockedOut
            }
            $output | Format-List
            
            # Additional logic for unlocking or deleting users as previously described
            ...
        }
    } else {
        Write-Host "No users found matching the search criteria." -ForegroundColor Yellow
    }
}
```

In this modification:

1. **Wildcards**: The variable `$wildcardQuery` is defined as `"*$searchQuery*"`. This means that if you input "tom", the search query becomes `*tom*`, which matches any username that includes "tom" in any part of the name, such as "tom", "tommy", or "jerrytom".

2. **MemberOf Field**: Assuming you want to list all group memberships in a user-readable format, `MemberOf` is joined using `', '` to separate group DN strings for better readability.

3. **Search Query Adjustment**: The `Get-ADUser` command's filter is adjusted to use `$wildcardQuery`, enhancing your search capabilities to include partial matches.

This enhancement to your `Search-User` function allows for more flexible user searches, accommodating variations in user account names.
User: ... : The term '...' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if 
a path was included, verify that the path is correct and try again.
At C:\Users\Administrator\Desktop\test.ps1:63 char:13
+             ...
+             ~~~
    + CategoryInfo          : ObjectNotFound: (...:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Assistant: The `...` notation in the script was used as a placeholder to indicate where additional logic for handling user decisions like unlocking or deleting accounts would be placed. Since PowerShell doesn't recognize `...` as valid syntax, you need to replace it with the actual logic necessary for your script's functionality. 

Here's how you might expand on that section to include unlocking and deleting the user account logic fully:

```powershell
function Search-User {
    Write-Host "Enter the 'User Management' section and select option 2: Search User"
    $searchQuery = Read-Host -Prompt "Enter username to search"
    
    # Adding wildcards around the search query to match similar names
    $wildcardQuery = "*$searchQuery*"
    
    # Search for users matching the query using wildcards
    $matchedUsers = Get-ADUser -Filter "SamAccountName -like '$wildcardQuery'" -Properties whenCreated, MemberOf, lastLogonDate, PasswordExpired, userAccountControl, LockedOut -ErrorAction SilentlyContinue
    
    if ($matchedUsers) {
        foreach ($user in $matchedUsers) {
            # Display the user's properties formatted similarly to the given example
            $output = @{
                Name = $user.sAMAccountName
                whenCreated = $user.whenCreated
                DistinguishedName = $user.DistinguishedName
                MemberOf = $user.MemberOf -join ', '
                lastLogonDate = $user.lastLogonDate
                PasswordExpired = $user.PasswordExpired
                userAccountControl = $user.userAccountControl
                LockedOut = $user.LockedOut
            }
            $output | Format-List
            
            # Check if the user account is locked
            if ($user.LockedOut) {
                $unlockChoice = Read-Host -Prompt "The account is locked. Do you want to unlock it? (Y/N)"
                if ($unlockChoice -eq 'Y') {
                    try {
                        Unlock-ADAccount -Identity $user
                        Write-Host "Account unlocked successfully." -ForegroundColor Green
                    } catch {
                        Write-Host "Failed to unlock account: $_" -ForegroundColor Red
                    }
                }
            }

            # Ask if the admin wants to delete the account
            $deleteChoice = Read-Host -Prompt "Do you want to delete this account? (Y/N)"
            if ($deleteChoice -eq 'Y') {
                try {
                    Remove-ADUser -Identity $user -Confirm:$false
                    Write-Host "Account deleted successfully." -ForegroundColor Green
                } catch {
                    Write-Host "Failed to delete account: $_" -ForegroundColor Red
                }
            }
        }
    } else {
        Write-Host "No users found matching the search criteria." -ForegroundColor Yellow
    }
}
```
In this revised script:
- Detailed logic has been provided for handling the user's choice to unlock or delete an account based on prompts.
- All placeholders indicating where logic should be added (`...`) have been replaced with actual operational commands to ensure the script runs without errors in PowerShell. 

Make sure to adjust this part of the script to match the specific operations and settings of your Active Directory environment.
Assistant: