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

Need Out-File formatting help.
Last Post 22 Apr 2008 08:14 PM by bsonposh. 4 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
flouieUser is Offline
New Member
New Member
Posts:1
Avatar

--
22 Apr 2008 06:38 PM  
Hello,

I'm a newbie to Powershell and I found this script to search for files containing SSN and it seems to work but my out-file seems to be unformatted and very hard to read.

Get-ChildItem  -rec -exclude *.exe,*.dll |select-string "[0-9]{3}[-| ][0-9]{2}[-| ][0-9]{4}" |out-file C:\1.txt

Can someone tell me how do I get the out-file to only list the path and file name of the file containing SSN? I think the problem might be that the path to most of those files are very long and can be nested like 6 sub-folders deep.

Thanks in advance.
smurawskiUser is Offline
New Member
New Member
Posts:46

--
22 Apr 2008 07:16 PM  
All you would need is to add a Select-Object into the pipeline.


Get-ChildItem  -rec -exclude *.exe,*.dll | select-string "[0-9]{3}[-| ][0-9]{2}[-| ][0-9]{4}" | select-object path, filename | out-file C:\1.txt


You could shorten the command line up with some aliases too..
 <br> dir  -rec -exclude *.exe,*.dll | select-string "[0-9]{3}[-| ][0-9]{2}[-| ][0-9]{4}" | select path, filename | out-file C:\1.txt <br> 


Good luck!
Steven Murawski
Co-Host - Mind of Root (www.mindofroot.com)
Host - PowerShell Basics (powershell-basics.com)
KColbyUser is Offline
New Member
New Member
Posts:11
Avatar

--
22 Apr 2008 07:40 PM  

Posted By smurawski on 04/22/2008 11:16 AM
You could shorten the command line up with some aliases too..

I would be careful with the Aliases.  They're great for command like usage, but I would strongly recommend against putting them in a Script file.  The reason for this is aliases are mutable.  You can change what an alias does and the command it points to.  Using the full command name helps to avoid this and helps ensure you're scripts run the same way everywhere.

Kevin Colby
Sr Solutions Engineer
SecureVantage Technologies
smurawskiUser is Offline
New Member
New Member
Posts:46

--
22 Apr 2008 07:58 PM  
I agree when it comes to using aliases and scripts. I should have been more explicit on that. I viewed the above command as used at the interactive prompt. Thanks for the catch!
Steven Murawski
Co-Host - Mind of Root (www.mindofroot.com)
Host - PowerShell Basics (powershell-basics.com)
bsonposhUser is Offline
Basic Member
Basic Member
Posts:392
Avatar

--
22 Apr 2008 08:14 PM  
IMO this would work better. Select-String is going to hose the object.


$regex = "<Your Regex Here>"
Get-Childitem -rec -exclude *.exe,*.dll | where { $_ | select-string $regex } | select Directory,Name | out-file C:\1.txt 
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
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