Query – import-csv

Welcome Forums General PowerShell Q&A Query – import-csv

Viewing 3 reply threads
  • Author
    Posts
    • #264680
      Participant
      Topics: 1
      Replies: 1
      Points: -7
      Rank: Member

      Hi, just a quick one.

      This does work, just wondered if there was a better way to achieve this

      While creating distribution groups in o365, I’m taking the Owners column that has a list of comma separated ‘firstname surname’ and I want to convert that to our corporate email address in the correct format to add the managedBy users

      "" }[/crayon]

       

      • This topic was modified 1 month, 1 week ago by dj.63. Reason: Code is not showing correctly
      • This topic was modified 1 month, 1 week ago by dj.63.
      • This topic was modified 1 month, 1 week ago by dj.63.
      • This topic was modified 1 month, 1 week ago by dj.63.
      • This topic was modified 1 month, 1 week ago by dj.63.
    • #264710
      Participant
      Topics: 2
      Replies: 380
      Points: 513
      Helping Hand
      Rank: Major Contributor

      The first replace() looks like it’s redundant as you’re not specifying a delimiter for Import-CSV.  If you have commas in your column you’re only going to get the first item in the comma separated list plus the domain.

       

      • This reply was modified 1 month, 1 week ago by Matt Bloomfield. Reason: Formatting
    • #264725
      Participant
      Topics: 1
      Replies: 1
      Points: -7
      Rank: Member

      Thanks for the reply, sorry meant turning

      user1 surname1,user2 surname2,user3 surname3

      to

      [email protected],[email protected],[email protected]

      So its multivalued

      This worked, but is it the best option?

      $owners = $($_.Owners.Replace(‘,’,’@emaildomain.com,’).Replace(‘ ‘,’.’)+”@emaildomain.com”)
      $owners = $owners -split ‘ *, *’
      $members = $($_.Members.Replace(‘,’,’@emaildomain.com,’).Replace(‘ ‘,’.’)+”@emaildomain.com”)
      $members = $members -split ‘ *, *’

       

    • #264773
      Participant
      Topics: 2
      Replies: 380
      Points: 513
      Helping Hand
      Rank: Major Contributor

      I don’t think there’s anything wrong with it 🙂

      You could keep it all on one line and pipe the split objects to another ForEach-Object which I think helps readability.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.