TenBrink Tech Technology | Life

20Aug/07

More PowerShell One-Liners

A one-liner used today while fiddling around with a robocopy output from moving some PST files around. I wanted to take the messy robocopy log file and just extract the PST file names and paths from the log file (yes, I know, they could have used some of the robocopy switches like /NS /NJH /NJS, but they wanted the other info for other purposes --- all I wanted was the filenames).

A little PowerShell, combined with some .NET regex fun did the trick. The breakdown...

  1. Get the text file contents
  2. Grab only the lines with the format of \\.pst
  3. Split those lines (to get rid of the whitespace and size output) at the "\\"
  4. Add the path (which is all that is left over now in $1[1]) to a list variable $files, adding the \\ along the way.

get-content .\pstrobocopy.txt | where { $_  -match "\\\\.+?\.pst$" } ; foreach { $line = [regex]::split($_,'\\\\'); $files += "\\" + $line[1] }

  • Share/Bookmark
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.