Share via


How to manipulate strings using PowerShell?

This is simple method to manipulate strings in text file using PowerShell

Requirement: Need to create a MailBox using Exchange PowerShell. The Script should read the log text file and get the User ID to create.

Note: I am not describing about exchange PowerShell mail box creation. This covers only Windows PowerShell module to fetch the required content in the text file

Log Text File Format:

123456, User ID Created
345678, User ID Created

Task: Fetch Only the User ID '123456'. The catch here is user ID format and length may change in future and customer don't want to change the script every now and then.

Solution:

$string = Get-Content C:\Temp\SSOFile.txt
$delimeter = ","
foreach($line in $string)
{$ID = $line.Substring(0,$line.IndexOf($delimeter)).TrimEnd()
 $ID}

OutPut:
123456
345678

Modify and get the output in other text file for further processing.


Website Traffic Statistics