0
$version = Get-EventLog 
 -Newest 1 
 -ComputerName $systemnummer 'Symantec Endpoint Protection Client' 
 -Message "*Version*" | Select message 
[string]$version = $version
$version = $version.Split(":")

After getting the Eventlog Entry $version contains the following string: "@{Message=New virus definition file loaded. Version: 150317001.}"

How can i split the String to get only the number "150317001"?

Inspector Squirrel
2,5462 gold badges29 silver badges38 bronze badges
asked Mar 19, 2015 at 12:09

3 Answers 3

1

The problem is that your message string is still a property (Message) of the object, so you need to reference it by that property name:

$version = Get-EventLog 
 -Newest 1 
 -ComputerName $systemnummer 'Symantec Endpoint Protection Client' 
 -Message "*Version*" | Select message 
$version = $version.Message.Split(":")[1]

Or use Select -ExpandProperty to get just the value:

$version = Get-EventLog 
 -Newest 1 
 -ComputerName $systemnummer 'Symantec Endpoint Protection Client' 
 -Message "*Version*" | Select -ExpandProperty message 
$version = $version.Split(":")[1]
answered Mar 19, 2015 at 13:02

Comments

0

Just use regex for this. Here code for your example:

$content = '@{Message=New virus definition file loaded. Version: 150317001.}';
$regex = 'version\s*:\s*(\d+)';
$resultingMatches = [Regex]::Matches($content, $regex, "IgnoreCase")
$version = $resultingMatches[0].Groups[1].Value
answered Mar 19, 2015 at 12:18

Comments

0

This should work:

$version = Get-EventLog -Newest 1 -ComputerName $systemnummer 'Symantec Endpoint Protection Client' -Message "*Version*" | Select message 
$ver = $version.message -replace ".*(\d+).*", "`1ドル"
Matt
47k9 gold badges90 silver badges125 bronze badges
answered Mar 19, 2015 at 12:14

3 Comments

i tried, but im sorry... your $ver seems to be empty
Don't cast to [string] before doing the code I added, just leave $version as it is when returned from Get-Eventlog
Consider using Select -expand message to just get the string back. Remove one hurdle.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.