C Suttie
C Suttie

Reputation: 23

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

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?

Upvotes: 1

Views: 97

Answers (1)

Jason
Jason

Reputation: 475

Give this a shot

$content = Get-content $localfolder$file | where-object { $_ -CMatch "0x00000000" }
$split_content = $content -split "successful"
$date = split_content[-9]

Upvotes: 1

Related Questions