$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
3 Answers 3
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
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
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
Manu El
i tried, but im sorry... your $ver seems to be empty
arco444
Don't cast to
[string]
before doing the code I added, just leave $version
as it is when returned from Get-Eventlog
Matt
Consider using
Select -expand message
to just get the string back. Remove one hurdle.lang-bash