use powershell to edit proxyadresses in user account in Active Directory


We have integrated office365 in AD, unfortunatelly when adding a new user and email adress for him I must to edit manually proxyadresses field in atribute editor, is very frustrating and takes a long time ;).

Below is the code to make it faster, the code must be executed in the order shown below.

I would like to make the task even easier and here’s a question for you

Is possible to make in powershell a text box so when I enter a login user (e.g. john.smith) in a filed and hit enter or ok button the following code will be executed and the variable I enter will replace john.smith variable in the code below


Set-ADUser -identity john.smith -UserPrincipalName;
Set-ADUser -Identity john.smith -Add @{'proxyAddresses'=""};
Set-ADUser -Identity john.smith -Add @{'proxyAddresses'=""};
Add-ADGroupMember -Identity g_o365_sync_test -Members john.smith;
Start-ADSyncSyncCycle -PolicyType deltaStart-ADSyncSyncCycle -PolicyType delta


Thank you in advance for your help :slight_smile:

If you must have a text box, you’ll need to use a Windows Form object. See System.Windows.Forms PoshGUI can help you make a simple form. If you are ok with just prompting inside the shell, you can use Read-Host

Yes. Read-Host is a basic prompt, but it’s free text so you need to validate they are putting the correct information in. In this case, you would just do a Get-ADUser to find the user. One you you have the user, then that can be used in subsequent commands. The Set-ADUser should be a single command, no need to do 3 separate commands. Note that this is not test and -WhatIf is added to validate before you execute the commands in any environment.

$name = Read-Host -Prompt 'Enter a name' 

$adUser = Get-ADUser -Filter {SamAccountName -eq $name} 

if ($adUser) {

    $setParams = @{
        Identity          = $adUser 
        UserPrincipalName = ('{0}' -f $name)
        Add               = @{'proxyAddresses'="SMTP:$","smtp:$"}

    Set-ADUser @setParams -WhatIf

    Add-ADGroupMember -Identity g_o365_sync_test -Members $adUser -WhatIf
    Start-ADSyncSyncCycle -PolicyType deltaStart-ADSyncSyncCycle -PolicyType delta
else {
    'Name {0} was not found in Active Directory' -f $name