none
Change CustomAttribute value RRS feed

  • Question

  • Hi,

    I create a powershell script to update a dynamic distribution group in Exchange 2010.

    The script get the member of a users group and for each member the script change the custom attribute 5.

    So far this the script :

    #importe les commandes specifique a MS Exchange 2010
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 
    
    #importe les commandes spécifique à l'AD
    import-module activedirectory 
    
    #declaration varialble
    $memberGROUP = Get-ADGroupMember VPN
    
    foreach ($member in $memberGROUP)
    	{
    		$user = $member.name
    		Set-Mailbox -Identity $user -CustomAttribute5 "vpn"	
    	}

    I would like to test if the "CustomAttribute5" is not equal to "vpn" then if it is true the script change the value to "vpn".

    Can you help me ?

    Friday, February 14, 2014 2:23 PM

All replies

  • Hi,

    I try with the code below but it doesn't work.

    foreach ($member in $memberGROUP)
    	{
    		$user = $member.name
    		$value = Get-Mailbox -Identity $user | fl CustomAttribute5
    		if ($value -eq "vpn")
    			{
    				Set-Mailbox -Identity $user -CustomAttribute5 "vpn"
    			}
    	}

    Any ideas ? 
    • Edited by GenePatton Tuesday, February 18, 2014 11:17 AM
    Tuesday, February 18, 2014 11:17 AM
  • Hi GenePatton,

    You are using the wrong comparison operator. Try "-ne" instead of "-eq" as you wish to update CustomAttribute5 only if its value does not equals "vpn".

    Best Regards,

    Charles Ngor

    Refresh IT Solutions

    Tuesday, February 18, 2014 12:05 PM
  • you are targeting the mailbox, but custom attribute 15 is an AD attribute - that is created when you install exhcnage in the environment.

    this script will do what you want

    #importe les commandes specifique a MS Exchange 2010
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 
    
    #importe les commandes spécifique à l'AD
    import-module activedirectory 
    
    #declaration varialble
    $memberGROUP = Get-ADGroupMember VPN
    
    foreach ($member in $memberGROUP)
    	{
    		$user = $member.name
    		#Set-Mailbox -Identity $user -CustomAttribute5 "vpn"	
    		Set-ADUser $user -add @{extensionattribute15="vpn"}
    	}
    you will notice I have commented out your line and replaced it with set-aduser - this will set the property on the user account. you can then use this value for your dynamic DL.


    Regards,

    Denis Cooper

    MCITP EA - MCT

    Help keep the forums tidy, if this has helped please mark it as an answer

    My Blog

    LinkedIn:

    Tuesday, February 18, 2014 1:14 PM
  • Hi,

    It 's not working. the script keep re-wrinting cutomAttribute5 for all users in the group "VPN"

    Best regards

    GenePatton

    • Edited by GenePatton Tuesday, February 18, 2014 1:56 PM
    Tuesday, February 18, 2014 1:55 PM
  • sorry I wrote 15 instead of 5, just change it to 5

    Regards,

    Denis Cooper

    MCITP EA - MCT

    Help keep the forums tidy, if this has helped please mark it as an answer

    My Blog

    LinkedIn:

    Tuesday, February 18, 2014 2:04 PM
  • #importe les commandes specifique a MS Exchange 2010
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 
    
    #importe les commandes spécifique à l'AD
    import-module activedirectory 
    
    #declaration varialble
    $memberGROUP = Get-ADGroupMember VPN
    
    foreach ($member in $memberGROUP)
    	{
    		$user = $member.name
    		#Set-Mailbox -Identity $user -CustomAttribute5 "vpn"	
    		Set-ADUser $user -replace @{extensionattribute5="vpn"}
    	}
    there you go - I've also changed the add to replace

    Regards,

    Denis Cooper

    MCITP EA - MCT

    Help keep the forums tidy, if this has helped please mark it as an answer

    My Blog

    LinkedIn:

    Tuesday, February 18, 2014 2:06 PM
  • Hi,

    Here is the new code with the modification you propose :

    #importe les commandes specifique a MS Exchange 2010 Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 #importe les commandes spécifique à l'AD import-module activedirectory #declaration varialble $memberGROUP = Get-ADGroupMember VPN

    foreach ($member in $memberGROUP) { $value = Get-ADUser $member | fl extensionattribute5 if ($value -ne "vpn") { Set-ADUser $member -replace @{extensionattribute5="vpn"} Write-host "hello" } }

    It still doesn't work. I keep having "Hello" for each user ; I should have no "hello" at all

    GenePatton

    Friday, February 21, 2014 12:36 PM
  • Your code is wrong. I can't update it at the minute as in on my phone. The code I provided does what you asked for though.

    Regards,

    Denis Cooper

    MCITP EA - MCT

    Help keep the forums tidy, if this has helped please mark it as an answer

    My Blog

    LinkedIn:

    Friday, February 21, 2014 1:24 PM
  • #importe les commandes specifique a MS Exchange 2010
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 
    
    #importe les commandes spécifique à l'AD
    import-module activedirectory 
    
    #declaration varialble
    $memberGROUP = Get-ADGroupMember VPN
    foreach ($member in $memberGROUP)
    	{
    		$value = Get-ADUser $member | Select-Object extensionattribute5
    		if ($v_.extensionattribute5 -ne "vpn")
    			{
    				Set-ADUser $member -replace @{extensionattribute5="vpn"}
    				Write-host "hello"
    			}
    	}
    Do you still require further help with this?

    Regards,

    Denis Cooper

    MCITP EA - MCT

    Help keep the forums tidy, if this has helped please mark it as an answer

    Blog: http://www.windows-support.co.uk  Twitter:   LinkedIn:

    Thursday, February 27, 2014 10:42 PM