Setting a list of aliases from txt file using quest

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Simon Wåhlin Simon Wåhlin 1 year, 11 months ago.

  • Author
    Posts
  • #21812
    Profile photo of lemonade
    lemonade
    Participant

    Just trying to simplify an admin task. I need to take the user account logon name firstnamespacesurname and then create an alias firstname.surname.

    If I process on a specific OU its fine

    Add-PSSnapin Quest.ActiveRoles.ADManagement
    Get-QADUser -enabled -sl 0 -LdapFilter '(mail=*)' -searchroot "OU=etc,OU=etc,dc=etc,dc=etc" |`
        foreach-object{ ( $alias = $_.sAMAccountName -replace " ","." )
                Set-QADUser -Identity $_ -ObjectAttributes @{mailNickname = $alias}
    
    
    However, if I try and process from a list of users from csv or txt file it fails.
    
    Add-PSSnapin Quest.ActiveRoles.ADManagement
    Import-Csv -path "$Env:userprofile\Desktop\alias.csv" |`
        foreach-object { ( $alias = $_.sAMAccountName -replace " ",".") |`
            Set-QADUser -Identity $_ -ObjectAttributes @{mailNickname = $alias}}
    
  • #21815
    Profile photo of Simon Wåhlin
    Simon Wåhlin
    Participant

    There is a pipe char at the end of the third row in your second example.

    This:

    Add-PSSnapin Quest.ActiveRoles.ADManagement
    Import-Csv -path "$Env:userprofile\Desktop\alias.csv" |`
        foreach-object { ( $alias = $_.sAMAccountName -replace " ",".") |`
            Set-QADUser -Identity $_ -ObjectAttributes @{mailNickname = $alias}}
    

    should be:

    Add-PSSnapin Quest.ActiveRoles.ADManagement
    Import-Csv -path "$Env:userprofile\Desktop\alias.csv" |`
        foreach-object { ( $alias = $_.sAMAccountName -replace " ",".") 
            Set-QADUser -Identity $_ -ObjectAttributes @{mailNickname = $alias}}
    

    Also, depending on how your csv is designed you might want to use -Identity $_.sAMAccountName for the Set-QADUser command.

  • #21817
    Profile photo of lemonade
    lemonade
    Participant

    Tried all kinds of ways, if i leave as $_ and remove the second pipe as suggested i get this error

    Set-QADUser : Cannot bind parameter 'Identity'. Cannot convert the "@{user 1=user 2}" value of type "System.Management.Automation.PSCustomObject" to type 
    "Quest.ActiveRoles.ArsPowerShellSnapIn.Data.IdentityParameter".
    At C:\setalias.ps1:4 char:31
    +         Set-QADUser -Identity $_ -ObjectAttributes @{mailNickname = $alias}}
    +                               ~~
        + CategoryInfo          : InvalidArgument: (:) [Set-QADUser], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.SetUserCmdlet
    

    If i set to $_.sAMAccountname i get this

    Set-QADUser : Cannot validate argument on parameter 'Identity'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
    At C:\setalias.ps1:4 char:31
    +         Set-QADUser -Identity $_.sAMAccountName -ObjectAttributes @{mailNickname ...
    +                               ~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Set-QADUser], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.SetUserCmdlet
    
  • #21822
    Profile photo of Simon Wåhlin
    Simon Wåhlin
    Participant

    I read up on the Set-QADUser, it only accepts DN, SID, GUID, UPN or Domain\UserName for the parameter -Identity
    You need to have one of those in your CSV, if you don't you could append the domain name like this:

    $DomainName = 'mydomain'
    Add-PSSnapin Quest.ActiveRoles.ADManagement
    Import-Csv -path "$Env:userprofile\Desktop\alias.csv" |`
        foreach-object { ( $alias = $_.sAMAccountName -replace " ",".") 
            Set-QADUser -Identity ('{0}\{1}' -f $DomainName, $_.sAMAccountName) -ObjectAttributes @{mailNickname = $alias}}
    

You must be logged in to reply to this topic.