Tips and Tricks

Tips and Tricks
Don Jones
PowerShell for Admins

Installing PowerShell v5? Be a Little Careful, OK?

I’m getting a lot of questions from folks, via Twitter and other venues, regarding Windows Management Framework 5.0 - which is where PowerShell v5 comes from. It’s awesome that people are installing v5 and kicking the tires - however, please help spread the word: v5 is a preview. It isn’t done, and it isn’t guaranteed bug-free. It shouldn’t be installed on production computers until it’s officially released. v5 doesn’t install ‘side by side’ with v3 or v4.

Steven Murawski
Tips and Tricks

Going Deeper on DSC Resources

Desired State Configuration is a very new technology and declarative configuration management is a very young space yet. We (Microsoft and the community) are still figuring out the best structure for resources, composite configurations, and other structures. That said, there are certain viewpoints that I’ve come to, either from hands on experience or in watching how other communities (like the Puppet community or Chef community) handle similar problems. How Granular Should I Get?

Don Jones
PowerShell for Admins

Why Get-Content Ain't Yer Friend

Well, it isn’t your enemy, of course, but it’s definitely a tricky little beast. Get-Content is quickly becoming my nemesis, because it’s sucking a lot of PowerShell newcomers into its insidious little trap. Actually, the real problem is that most newcomers don’t really understand that PowerShell is an object-oriented, rather than a text-oriented shell; they’re trying to treat Get-Content like the old Type command (and why not? type is an alias to Get-Content in PowerShell, isn’t it?

Steven Murawski
Tips and Tricks

Desired State Configuration – General Availability Changes

PowerShell DSC, along with Windows Server 2012 R2 has reached General Availability!  Yay! However, there is (at least one so far) breaking change** **in Desired State Configuration (DSC). Fortunately, the change is in an area I haven’t blogged about yet.. creating custom resources.  Unfortunately, it does mean I’ll have to update the GitHub repository and all my internal content (should be done by early next week). The short version is that DSC resources are now resources inside modules, rather than each resource being independent modules.

Don Jones
PowerShell for Admins

Regular Expressions are a -replace's best friend

Are you familiar with PowerShell’s -replace operator? "John Jones" -replace "Jones","Smith" Most folks are aware of it, and rely on it for straightforward string replacements like this one. But not very many people know that -replace also does some amazing stuff using regular expressions. "192.168.15.12,192.168.22.8" -replace "\.\d{2}\.","10" That’d change the input string to “192.168.10.12,192.168.10.8,” replacing all occurrences of two digits, between periods, to 10. The 12 would be skipped because it isn’t followed by a period, as specified in the pattern.

Don Jones
PowerShell for Admins

Why Doesn't My ValidateScript() work correctly?

I’ve received a few comments from folks after my observations on the Scripting Games Event 1. In those observations, I noted how much I loved: [ValidateScript({Test-Path $_})][string]$path As a way of testing to make sure your -Path parameter got a valid value, I love this. I’d never thought of it, and I plan to use it in classes. I may write a book about it someday, or maybe even an ode.

Don Jones
PowerShell for Admins

What are Your PowerShell Newbie Gotchas?

I’m putting together a list of common “gotchas” for PowerShell, mainly things that affect newcomers. So far, I’ve got: Piping the output of a Format cmdlet to nearly anything else Using -contains instead of -like Selecting a subset of object properties and then trying to sort/fiter on a now-missing property Wrong syntax for -filter parameters on various commands Commands that don’t produce pipeline output (e.g., piping Export-CSV to something) Using ConvertTo-HTML without -Fragment and appending multiple pages in one file Confusion with ( [ { and the other punctuation Concatenating strings (hard) vs.

Don Jones
Tips and Tricks

PowerShell.org Forums Etiquette

Folks often ask for some advice on what to do, and what not to do, in the forums. Here are some suggestions. Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need - nobody will think you’re stupid, and the forums are all about asking questions. Just ask. Try to avoid using obscure or punctuation aliases (like ? and %) - use command names instead. It makes your post easier for everyone, including n00bs, to follow.