So I'm trying to run a script that searches a particular file for the phrase "Default Printer: PRINTERNAME". What I have so far is:
cls
$file = "c:\temp\print.log"
Select-String -pattern "Default Printer:..." -path $File
This is returning a lot more data than I'd like:
c:\temp\print.log:864:9/9/2014 10:01:18 PM: Default Printer: HEIAISNF004
c:\temp\print.log:890:9/10/2014 8:27:08 AM: Default Printer: HEIAISNF004
c:\temp\print.log.log:944:9/11/2014 8:06:45 AM: Default Printer: HEIAISNF004
c:\temp\print.log:1012:9/12/2014 7:51:15 AM: Default Printer: HEIAISNF004
c:\temp\print.log:1108:9/16/2014 7:38:20 AM: Default Printer: HEIAISNF004
c:\temp\print.log:1134:9/18/2014 8:42:46 AM: Default Printer: HEIAISNF004
c:\temp\print.log:1244:9/24/2014 4:55:44 AM: Default Printer: HEIAISNF004
I only want the last instance of the pattern (which happens to be the most recent), and I want to output the value (in this case HEIAISNF004) to a csv file.
Any ideas on how I can do that?