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"?

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]
Sign up to request clarification or add additional context in comments.

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

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"

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

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.