header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Strip Result of Select-String to a file
Last Post 11 Aug 2008 08:16 PM by halr9000. 1 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
edm365f31User is Online
New Member
New Member
Posts:38
Avatar

--
11 Aug 2008 07:31 PM  

How do strip a result of select-string to a file without the path

I need to select certain types of Servers output to another text file

select-string -path C:\Powershell\Host\winservers2.txt -pattern ^hostname

C:\Powershell\Host\winservers2.txt:562:hostname00
C:\Powershell\Host\winservers2.txt:563:hostname01
C:\Powershell\Host\winservers2.txt:564:hostname02
C:\Powershell\Host\winservers2.txt:565:hostname04

how do i pass just the hostname* to text without the C:\Powershell\Host\winservers2.txt:565

 

halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
11 Aug 2008 08:16 PM  
Looks like this output is cleaned up by default with powershell v2, so that's good to know. for v1, look at the 'Line' property of the MatchInfo objects which are returned. e.g.

$results = select-string -path myfile.txt -pattern 'hostname'
$results | select line
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer