If I input a proxyaddress that does not already exist I get the write-host saying "ProxyAddress Not Found". However if it does exist then I get an error:
get-aduser : One or more properties are invalid.
Parameter name: jmanwell@domain.net
At D:\Users\bhart.DIFC\Dropbox\Scripts\Create_New_AD_user_O365.ps1:36 char:1
+ get-aduser -filter * -properties $proxyaddress
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADUser], ArgumentException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.GetADUser
I'd obviously like for this part to say the address already exists and re-prompt me to input a correct one. Back in the day that'd be a goto line whatever, but I doubt that works in PS lol.
while (Get-ADuser -filter * -Properties ProxyAddresses|?{$_.proxyaddresses -contains $proxyaddress})
{
$proxyaddress = read-host "$proxyaddress is already in use, please try another one"
}
Write-Host "$proxyaddress is not used yet."
I will comment out the top part that was in my original and give it a test.
Ben Hart
ASKER
And it still works. interesting but thanks for letting me know.
Qlemo
With the partitially replaced code you are doing the AD query 3 times. Only once is sufficient :D.