PowerShell - Using Variables to Delete SMTP Proxy Addresses in AD
-
Probably either
"smtp:$($GivenName).$($Surname)@$($Domain)"
Or
('smtp:' + $GivenName + '.' + $Surname + '@' + $Domain)
-
Did you test your string creation on its own?
-
@flaxking said in PowerShell - Using Variables to Delete SMTP Proxy Addresses in AD:
Probably either
"smtp:$($GivenName).$($Surname)@$($Domain)"
Or
('smtp:' + $GivenName + '.' + $Surname '@' + $Domain)
The first option yields the same results. The second, errors out.
-
@flaxking said in PowerShell - Using Variables to Delete SMTP Proxy Addresses in AD:
Did you test your string creation on its own?
I have not and am not exactly sure how to.
-
@wrx7m said in PowerShell - Using Variables to Delete SMTP Proxy Addresses in AD:
@flaxking said in PowerShell - Using Variables to Delete SMTP Proxy Addresses in AD:
Probably either
"smtp:$($GivenName).$($Surname)@$($Domain)"
Or
('smtp:' + $GivenName + '.' + $Surname '@' + $Domain)
The first option yields the same results. The second, errors out.
Yeah, the second one was missing a +
-
You're also trying to put an object into a string, which will only work if that object it set to print out the value you're looking for by default
-
So in order to access the GivenName property on the object you have you would do
$GivenName.GivenName
you could just do:
$User = Get-ADUser -Identity $SamAccountName $User.GivenName $User.Surname
in which case your smtp string would be
"smtp:$($User.GivenName).$($User.Surname)@$Domain"
-
Powershell is object oriented, which is super important to realize when working with it, and that is what usually gives people the problem with it, if they do not have previous experience with objects. It makes a big learning curve increase.
On you 'Write-Host' test on your Set-ADUser command, you see "System.Collections.DictionaryEntry" because that is telling you what object is there. You're creating dictionary objects, so it's not going to automatically write out the contents of the dictionary.
-
So what you're looking at now is something like this:
Import-Module ActiveDirectory $SamAccountName = Read-Host -Prompt "SamAccountName" $Domain = Read-Host -Prompt "Type the domain of the address you wish to DELETE" $user = Get-ADUser -Identity $SamAccountName Set-ADUser $user -Remove @{proxyAddresses="smtp:$($user.GivenName).$($user.Surname)@$Domain"}
-
@flaxking said in PowerShell - Using Variables to Delete SMTP Proxy Addresses in AD:
if they do not have previous experience with objects
Describes me. lol