This is a small part of a larger script
I am searching for an existing SMTP address and if it is found, then adding a "incremented" number as a prefix to the address and searching again. When I find an address that doesn't exist I wish to use this "New" address further in the script.
Here is the code I am having issues with:
# This portion of the Script starts with a 'valid' Mail Contact Alias
$MailContactAlias = "JohnDoe@Contoso.com"
$NewMailContactSmtpAddress = (Get-MailContact $MailContactAlias).ExternalEmailAddress.SmtpAddress
$Val = 0
$Prefix = ($Val -as [string])
$NewMailContactSmtpAddress = $Prefix + $MailContactAlias
$MailContactAddress = Get-Recipient $NewMailContactSmtpAddress -ErrorAction SilentlyContinue
# Pause inserted for testing
if ($MailContactAddress -eq $Null)
$MailContact = "NotFound"
$MailContact = "Exist"
While ($MailContact -eq "NotFound")
Even thought the variable $MailContact has a value of "NotFound" the Do ... While will not 'exit'.
I am still relatively new to scripting so all information is greatly appreciated.