none
Powershell - "-replace" in Description of AD Group RRS feed

  • Вопрос

  • Hi all!

    I try to replace the part of attribute "description" of ADgroup.

    For this purpose I created AD group with name "test" and description field "111-222-333

    and generated this command (from http://technet.microsoft.com/en-us/library/ee617199.aspx)

    get-adgroup test -Replace @{description='222', '999'}


    but I recieved an error, and I can't understand what's wrong.

    Get-ADGroup : A positional parameter cannot be found that accepts argument 'Sys
    tem.Collections.Hashtable'.
    At line:1 char:12
    + get-adgroup <<<<  test -Replace @{description='222', '999'}
        + CategoryInfo          : InvalidArgument: (:) [Get-ADGroup], ParameterBin
       dingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDire
       ctory.Management.Commands.GetADGroup

    Need your help

    19 июля 2012 г. 11:28

Ответы

  • 1) Description is not a multi-value parameter

    2) Use Set-AdGroup

    get-adgroup test | Set-AdGroup -Replace @{description='222'}

    or

    Set-AdGroup test -Replace @{description='222'}

    To replace part of attribute:

    Get-ADGroup test -Properties description | Foreach {
    	$newdesc = $_.description.replace("999","123")
    	Set-ADGroup  $_ -replace @{description = $newdesc}
    }

    • Изменено KazunEditor 19 июля 2012 г. 12:07
    • Помечено в качестве ответа Денис Аз 20 июля 2012 г. 9:07
    19 июля 2012 г. 11:42
    Отвечающий
  • It's woks and i'm sure.

    PS C:\Windows\system32> Get-ADGroup fla
    
    
    DistinguishedName : CN=Fla,OU=Global,DC=contoso,DC=com
    GroupCategory     : Security
    GroupScope        : Global
    Name              : Fla
    ObjectClass       : group
    ObjectGUID        : cfd10d28-bc9a-4485-8ed4-4419c04cacb7
    SamAccountName    : Fla
    SID               : S-1-5-21-426877971-1972103978-3236753350-1630
    
    
    
    PS C:\Windows\system32> Get-ADGroup fla -Properties description | ft description
    
    description
    -----------
    
    
    
    PS C:\Windows\system32> Get-ADGroup fla | Set-ADGroup -Description "111-222-333"
    PS C:\Windows\system32> Get-ADGroup fla -Properties description | ft description
    
    description
    -----------
    111-222-333
    
    
    PS C:\Windows\system32> Get-ADGroup fla -Properties description | Foreach {
    >>     $newdesc = $_.description.replace("222","999")
    >>     Set-ADGroup  $_ -replace @{description = $newdesc}
    >> }
    >>
    PS C:\Windows\system32> Get-ADGroup fla -Properties description | ft description
    
    description
    -----------
    111-999-333

    • Помечено в качестве ответа Денис Аз 20 июля 2012 г. 9:07
    20 июля 2012 г. 8:35
    Отвечающий

Все ответы

  • 1) Description is not a multi-value parameter

    2) Use Set-AdGroup

    get-adgroup test | Set-AdGroup -Replace @{description='222'}

    or

    Set-AdGroup test -Replace @{description='222'}

    To replace part of attribute:

    Get-ADGroup test -Properties description | Foreach {
    	$newdesc = $_.description.replace("999","123")
    	Set-ADGroup  $_ -replace @{description = $newdesc}
    }

    • Изменено KazunEditor 19 июля 2012 г. 12:07
    • Помечено в качестве ответа Денис Аз 20 июля 2012 г. 9:07
    19 июля 2012 г. 11:42
    Отвечающий
  • It doesn't works. Just nothing happens without errors.

    Are you sure that this line takes DESCRIPTION attribute, but not GROUP?

     
    Get-ADGroup test -Properties description
    20 июля 2012 г. 8:22
  • It's woks and i'm sure.

    PS C:\Windows\system32> Get-ADGroup fla
    
    
    DistinguishedName : CN=Fla,OU=Global,DC=contoso,DC=com
    GroupCategory     : Security
    GroupScope        : Global
    Name              : Fla
    ObjectClass       : group
    ObjectGUID        : cfd10d28-bc9a-4485-8ed4-4419c04cacb7
    SamAccountName    : Fla
    SID               : S-1-5-21-426877971-1972103978-3236753350-1630
    
    
    
    PS C:\Windows\system32> Get-ADGroup fla -Properties description | ft description
    
    description
    -----------
    
    
    
    PS C:\Windows\system32> Get-ADGroup fla | Set-ADGroup -Description "111-222-333"
    PS C:\Windows\system32> Get-ADGroup fla -Properties description | ft description
    
    description
    -----------
    111-222-333
    
    
    PS C:\Windows\system32> Get-ADGroup fla -Properties description | Foreach {
    >>     $newdesc = $_.description.replace("222","999")
    >>     Set-ADGroup  $_ -replace @{description = $newdesc}
    >> }
    >>
    PS C:\Windows\system32> Get-ADGroup fla -Properties description | ft description
    
    description
    -----------
    111-999-333

    • Помечено в качестве ответа Денис Аз 20 июля 2012 г. 9:07
    20 июля 2012 г. 8:35
    Отвечающий
  • Sorry, Kazun!!! You're right! This forks fine!

    I don't know where I made a mistake - your solution works now fine without errors, but yesterday I got nothing again and again!

    At first, I just used code, but nothing happened.... today I did every string manually with $a instead of $_ and it's works fine, then I copy\paste your code and it works!!! )

    Thank you very match for your help! :)


    20 июля 2012 г. 9:03