none
Adding attribute to a group of users with powershell RRS feed

  • Question

  • Hello there,

    I am new to powershell, I am trying to add the GUID to extensionAttribute2

    this works well for single user

    $uGuid = (Get-ADUser AppleHo | Select -Expand ObjectGUID).toString()
    set-ADUser -Identity AppleHo -Add @{extensionAttribute2=$uGuid}

    I attemp to do this for a OU of users, but hit in to error, can someone help me please?

    $uGuid =(
    
    Get-ADuser -Filter * -SearchBase "OU=Users,OU=IT,OU=Groups and External Service Accounts,DC=abc,DC=com,DC=eu"
    
    -Properties ObjectGUID,,| ForEach-Object {
    
    
     $_.ObjectGUID.toString()
    }
    )
    
    $uDname =(
    Get-ADuser -Filter * -SearchBase "OU=Users,OU=IT,OU=Groups and External Service Accounts,DC=abc,DC=com,DC=eu" -Properties SAMAccountName | ForEach-Object {
    $_.SAMAccountName
    }
    )
    
    
    Set-AdUser $uDName –add @{extensionAttribute2=$uGuid}

    if I  quote the above "Set-AdUser $uDName –add @{extensionAttribute2=$uGuid}" i get the output but not on the users in the OU

    cheers



    • Edited by cskeng Wednesday, July 5, 2017 3:34 AM update code format
    Tuesday, July 4, 2017 9:42 AM

Answers

  • Actually this should be enough:
    Get-ADuser -Filter * -SearchBase "OU=Users,OU=IT,OU=Groups and External Service Accounts,DC=abc,DC=com,DC=eu" -Properties ObjectGUID | 
        ForEach-Object { 
            Set-AdUser -Identity $_.SamAccountName -add @{extensionAttribute2=$_.ObjectGUID}
        }
    
    And please when you post code here in the forum format it as code with the code formatting option in the editor. Thanks

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    • Marked as answer by cskeng Wednesday, July 5, 2017 3:41 AM
    Tuesday, July 4, 2017 10:15 AM
  • Why would you want to do this:  The GUID is always attached to the account.

    Get-ADuser -Filter * -SearchBase 'OU=Users,OU=IT,OU=Groups and External Service Accounts,DC=abc,DC=com,DC=eu' | 
    	ForEach-Object {
    		$_ | Set-ADUser -Replace @{extensionAttribute2 = $_.ObjectGUID.Guid}
    	}
    

    You need to learn how to write PowerShell code as well as learning how to post code so that it is not broken.


    \_(ツ)_/


    • Edited by jrv Tuesday, July 4, 2017 10:21 AM
    • Marked as answer by cskeng Wednesday, July 5, 2017 3:41 AM
    Tuesday, July 4, 2017 10:18 AM

All replies

  • Actually this should be enough:
    Get-ADuser -Filter * -SearchBase "OU=Users,OU=IT,OU=Groups and External Service Accounts,DC=abc,DC=com,DC=eu" -Properties ObjectGUID | 
        ForEach-Object { 
            Set-AdUser -Identity $_.SamAccountName -add @{extensionAttribute2=$_.ObjectGUID}
        }
    
    And please when you post code here in the forum format it as code with the code formatting option in the editor. Thanks

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    • Marked as answer by cskeng Wednesday, July 5, 2017 3:41 AM
    Tuesday, July 4, 2017 10:15 AM
  • Why would you want to do this:  The GUID is always attached to the account.

    Get-ADuser -Filter * -SearchBase 'OU=Users,OU=IT,OU=Groups and External Service Accounts,DC=abc,DC=com,DC=eu' | 
    	ForEach-Object {
    		$_ | Set-ADUser -Replace @{extensionAttribute2 = $_.ObjectGUID.Guid}
    	}
    

    You need to learn how to write PowerShell code as well as learning how to post code so that it is not broken.


    \_(ツ)_/


    • Edited by jrv Tuesday, July 4, 2017 10:21 AM
    • Marked as answer by cskeng Wednesday, July 5, 2017 3:41 AM
    Tuesday, July 4, 2017 10:18 AM
  • Dear Jrv,

    Thank you for the help, I have reformted the codes

    the cloud service we are testing requires the GUID on the extensionAttribute to work.

    the code loops through with Set-ADUser : Insufficient access rights to perform the operation, will need to check this further with the team.

    Wednesday, July 5, 2017 3:45 AM
  • Hello Grube,

    Thank you for the help, I have reformatted the codes

    The code loops through with Set-ADUser : Insufficient access rights to perform the operation, will need to check this further with the team.


    Thank you for the help, the cloud service we are testing requires the GUID on the extensionAttribute to work.

    the code loops through with Set-ADUser : Insufficient access rights to perform the operation, will need to check this further with the team.

    Wednesday, July 5, 2017 3:47 AM