Selecting text from string


i'm searching event logs using get-eventlog.  want 1 word out of message of event (the printer name).  can select amount of characters want able select whole word because word can have multiple number of characters.  have.

$server = read-host "server name"
$message = get-eventlog system -entrytype information -computername $server -after (get-date).adddays(-1) | ?{$_.eventid -eq 10} | select-object -property timegenerated, username, @{n="printer: ";e = {(($_.message -split "\n") | select-string -pattern "printed on\s+(.....)").matches[0].groups[1].value}}
$message

thanks


smaximus7

in case \s+ match string non-whitespace characters. that'll work better \w+


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

DCOM received error "2147746132" from...

DFSR RPC replication errors 5014 1726 with large files over VPN

ADFS 3.0 Event ID 4625 | An Error occurred During Logon | Status: 0xC000035B