What is the equivalent of the split cmdlet in Powershell V2?

0

Currently I use the following to get the date of a log file:

$content = Get-content $localfolder$file | where-object { $_ -CMatch "0x00000000" }

In PS V3 and above I am able to use:

$date = $content.Split("successful")[-9]

Where this will get the last date from the log file.

Unfortunately for Powershell V2 it's not possible as this is not a valid command and due to company policies it's not possible to upgrade Powershell.

Anyone know what I could use instead of split to get this information?

powershell-v2.0
asked on Stack Overflow Sep 19, 2018 by C Suttie • edited Sep 19, 2018 by Michael Lihs

1 Answer

0

Give this a shot

$content = Get-content $localfolder$file | where-object { $_ -CMatch "0x00000000" }
$split_content = $content -split "successful"
$date = split_content[-9]
answered on Stack Overflow Sep 19, 2018 by Jason

User contributions licensed under CC BY-SA 3.0