appending text to automate domain name change and alias

Welcome Forums General PowerShell Q&A appending text to automate domain name change and alias

Viewing 1 reply thread
  • Author
    Posts
    • #241970
      Participant
      Topics: 1
      Replies: 0
      Points: -9
      Rank: Member

      Hi, I’m want make bulk changes using below script to change primary domain (the new domain) and make alias for old domain.  My csv has usernname, proxyaddress, proxyaddress2:

      $users = import-csv "c:\import.csv"
      
      ForEach ( $user in $users)
      {
      #define domain here
      $domain="@jhuccp.ng"
      
      #adding proxies
      $SMTP1="SMTP:"
      $SMTP2="smtp:"
      
      #adding all
      $SMTP1=$SMTP1 + $users.proxyaddress + $domain
      $SMTP2=$SMTP2 + $users.proxyaddress2 + $domain
      $email=$user.proxyaddress + $domain
      $upn=$email
      
      set-azureAduser $users.Username -add @{ProxyAddresses=$SMTP1}
      set-azureAduser $users.Username -add @{ProxyAddresses=$SMTP2}
      
      set-azureAduser $users.Username -emailaddress $email
      set-azureAduser $users.Username -userprincipalname $upn
      }
      

      there is error at below:

      Set-AzureADUser : A positional parameter cannot be found that accepts argument 'System.Object[]'.
      At line:18 char:1
      + set-azureAduser $users.Username -add @{ProxyAddresses=$SMTP1}
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidArgument: (:) [Set-AzureADUser], ParameterBindingException
      + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Open.AzureAD16.PowerShell.SetUser
      

      Please assist. thanks

      • This topic was modified 3 weeks, 2 days ago by kounzo95.
      • This topic was modified 3 weeks, 2 days ago by kounzo95.
      • This topic was modified 3 weeks, 2 days ago by kvprasoon. Reason: code formatting
      • This topic was modified 3 weeks, 2 days ago by kvprasoon.
    • #242021
      Participant
      Topics: 0
      Replies: 36
      Points: 336
      Helping Hand
      Rank: Contributor

      Hello kounzo95,
      Welcome to PowerShell.org forum.
      Please read Read Me Before Posting! You’ll be Glad You Did! and make sure to format your code property going forward.

      From the script it looks like you are operating with the collection of usernames ($users.proxyaddres ) not specific username that you have inside your foreach loop ($user).

      Try changing $users.proxyaddress to $user.

      Also I would move the domain definition outside of Foreach loop. Right now you are initializing $domain variable for each user.

      Hope that helps.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.