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.
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.
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,’