Basic Powershell Snippets

Michael Bourgon has a few Powershell snippets he wrote this week:

I needed to parse out a Unix filename from a file.  The original “ls” looked like this:

-rw-rw-r– 1 psabcderfg data 646621 Jul 19 16:25 myfile16071901.Z

The unix command to parse it would
cat $fl |awk ‘{print $9}’

And the powershell equivalent is:
$newfiles = get-content $fl | foreach {$_.split(” “)[8]}
(the number is 8 instead of 9 because powershell arrays start at 0)

Check all of them out.

Related Posts

Multithreading In Powershell

Andy Levy shows how to use the PoshRSJob module to implement multithreaded Powershell solutions: Let’s say you’ve got a lot of RSJobs. Or maybe long-running RSJobs. Wouldn’t a nice, user-friendly view of the progress be handy? You bet it would! This is both dense and verbose, but I wrote it really quickly and it works (but not just […]

Read More

Database Backups With dbatools

Garry Bargsley continues the 12 Days of dbatools series, this time taking a look at taking backups: We are on the home stretch and I have saved the last third of the series to cover some pretty cool/amazing commands.  Not that all 500+ commands are not cool/amazing but these last few are used continuously in […]

Read More


August 2016
« Jul Sep »