Below is a section of code I'm struggling to get operation. This is part of a larger script to create AD users. The purpose is to verify if the email address supplied exists and if it does, store it as the $UserManager (Manager) variable to be called upon when making the AD account.
I feel like I'm really close, I think I'm just struggling with the first part of the function or the initial query of the search. Do I need to specify a specific path?
Thank you for any assistance, this forum has allowed me to do some amazing things. Thank you all once again so much.
Credit for the base functionality of this script - https://github.com/HanSolo71/Active-Directory-Create-User-and-Mailbox/blob/master/CreateUserFullFunction.ps1
Import-Module ActiveDirectory
function ManagerCheck {
$UserManagerCheck = Get-ADUser -Filter {mail -eq "$UserManager"}
if ($UserManagerCheck = [string]::IsNullOrWhiteSpace($UserManagerCheck))
{
cls
$global:UserManager = (Read-Host -Prompt "Manager email address not found please check the email and try again")
$UserManagerCheck = $null
ManagerCheck
}
else
{
{continue}
CLS
}
}
$UserManager = @()
$UserManagerCheck = @()
$global:UserManager = @()
$EmployeeOU = "OU=Sample,OU=Path"
$UserManager = (Read-Host -Prompt "Please enter the users managers email address")
while ([string]::IsNullOrWhiteSpace($UserManager)) {$UserManager = Read-Host 'You left the email field empty, please input a manager email address'}
#Run manager check function
ManagerCheck
Write-Host
$UserManager
When running the command it prompts me to enter in an email address. It then immediately tells me "Manager email address not found please check the email and try again". It appears that it is not even searching for the supplied email address.
Any ideas?