Need to replace a delimeter and find out the AD group users

This topic contains 2 replies, has 3 voices, and was last updated by  postanote 6 days, 15 hours ago.

  • Author
    Posts
  • #87470

    raghavendra
    Participant

    Hi

    I have a .csv file with below content.

    XXXGRP1001 – XXX-AD-groupname
    XXXGRP1002 – XXX-AD-groupname
    XXXGRP1003 – XXX-AD-groupname
    XXXGRP1004 – XXX-AD-groupname
    XXXGRP1005 – XXX-AD-groupname

    I would like to replace "-" at 10th character with "," and split in to columns in three columns A(first 10 characters) and B(remaining characters) and Third column C will have AD-group users.
    Could you please let me know how to achieve this task. I am new to Powershell.

    Thanks
    Raghav

  • #87550

    Olaf Soyk
    Participant

    Is it a csv file or is it a text file? You could read the content of a text file with Get-Content and treat every line as needed or you could import your csv file with Import-CSV and treat the specific column as needed.

    You can use regular expressions to cut your string in pieces as needed or you could use substring method to do so.

  • #87575

    postanote
    Participant

    Example using just your string snippet...

    $StringToSplit = @'
    XXXGRP1001 – XXX-AD-groupname
    XXXGRP1002 – XXX-AD-groupname
    XXXGRP1003 – XXX-AD-groupname
    XXXGRP1004 – XXX-AD-groupname
    XXXGRP1005 – XXX-AD-groupname
    '@

    $StringToSplit -replace ' – ',',' -replace 'AD-','AD,'

    Results

    XXXGRP1001,XXX-AD,groupname
    XXXGRP1002,XXX-AD,groupname
    XXXGRP1003,XXX-AD,groupname
    XXXGRP1004,XXX-AD,groupname
    XXXGRP1005,XXX-AD,groupname

You must be logged in to reply to this topic.