PowerShell for Admins

PowerShell for Admins
Don Jones
PowerShell for Admins

FAQ: PowerShell on Linux/Mac

Be sure to check back often, as we’ll add to this.

So does this mean I’ll be able to run [add your favorite module name here] on Linux/Mac?

Likely not. PowerShell on Linux/Mac is, at present, “PowerShell Core,” which is a subset of the total Windows PowerShell product. Similar situation to PowerShell on Nano. So any module that requires something outside Core, won’t run.
And further, most modules have dependencies on underlying technologies in Windows. The SMBShare module, for example, depends on CIM classes that only exist on Windows.
So many add-in modules _won’t, _in fact work on Linux - because they’re designed to manage Windows machines. Over time, I’m sure we’ll see modules that only run on Linux and/or Mac, because they’re tied to dependencies on those operating systems.
Ideally, of course, you can always remote to the OS of your choice and run whatever commands it has. And from The Register:

Richard Siddaway
Announcements

PowerShell is Open Sourced

For those of you that have been at PowerShell Summits over the last few years you’ll have heard Jeffrey Snover state that he wanted to take PowerShell to other platforms.

Now its happened

Jeffrey has announced that an ALPHA release of PowerShell is now available for Linux and Mac.  Currently available for Ubuntu, Centos, Red Hat and Mac OS X with more to come

The announcement is at

https://azure.microsoft.com/en-us/blog/powershell-is-open-sourced-and-is-available-on-linux/

Also see PowerShell blog

Graham Beer
PowerShell for Admins

A date with PowerShell

At the beginning of July, we welcomed our 3rd son into the world. As days past my wife and I would say, “wow, he’s 11 days old. Can you believe it?!”. I’m sure parents out there are relating to this!
This gave me an idea for a fun script that would get your age in years, months and days, tell you how many days until your birthday and your star sign.
I wanted date of birth passed to the function as ‘dd/MM/yy’. To keep to this format, I’m using the ‘ValidatePattern’ Advanced Parameter with a Regular Expression (Regex). The regular expression, “^(0[1-9]|[12]\d|3[01])/(0[1-9]|1[0-2])/(\d{2})$”, will only allow a date in the format of 01/01/16, for example.
Briefly, here is regex syntax I used in some of the expression:
^ Start of string
( .. ) Capturing group
(0[1-9] Match two digits that make up the day. This accepts numbers from 01 to 09
| Acts like a Boolean OR.
/d match any digital character
[12] match any character in the set
/ used to divide the date numbers
{2} Exactly two times
$ End of string
Now that my function parameter variable $Bday has a date, its passed to get-date to be converted from a string to a date. The date in variable $cDate will look like this, ‘01 January 2016 00:00:00’. The next line in the code will use todays date and subtract the date passed in $cDate variable. The $diff variable will contain the following data which we will use to get our age in years, months and days:
Days : 212
Hours : 12
Minutes : 40
Seconds : 20
Milliseconds : 533
Ticks : 183624205335135
TotalDays : 212.528015434184
TotalHours : 5100.67237042042
TotalMinutes : 306040.342225225
TotalSeconds : 18362420.5335135
TotalMilliseconds : 18362420533.5135
I’ve contained this first part in our Begin block. The Process block does the main code.
Now I need to get my age in Years, Months and Days. This is where the [math] data type is used. I’m using the ‘Truncate’ property as I don’t want to do anything fancy like round up my numbers. Adding the .typename of Days to my $diff variable and dividing by $daysInYear variable I can get my age in years.
The next two, months and days required a tweak to the algorithm.
I ended up using a maths term called a ‘Mod’. Now I’m not talking about youth culture and style in the sixties (Mods and rockers anyone ??), but the Modulus Math Operator. Basically the Modulus Operator returns the remainder when the first number is divided by the second. So for example:
1 mod 3 = 1 (or 1 % 3 = 1)
2 mod 3 = 2
3 mod 3 = 0
4 mod 3 = 1
The operator sign used is % for Modulus. Not to be confused for the alias of foreach in PowerShell. For days in a month, I used the average of 30.
I thought it would be fun to add the star sign as well. I was after something that could tell me, “is this date in this date range?”. One of the properties of ‘get-date’ is DayOfYear.
Finding if a number is in a range is pretty straight forward, For example:

Don Jones
PowerShell for Admins

What are your "known problems" (solved) in DSC?

I’m collecting a list of known problems in DSC v5 _that have been solved. _Like the infamous “MI RESULT 12” error that could happen if you upgraded from prerelease v5 to production preview. I’m going to document these in “The DSC Book,” including in its free sample version, to help preserve these things in one place.
Again - these need to be solved problems. Just drop as much description as you can into a comment here, and feel free to link to the fix, or to a discussion thread on the problem.
And please - pass this around. If you’ve never had a chance to contribute to “the community” before, now’s a great time. Even if it’s a problem that you know doesn’t exist in the current v5 release, let’s please just document its former existence.
Thanks!

pscookiemonster
PowerShell for Admins

Deploying Modules to the PowerShell Gallery

So! We’ve talked about continuous integration and deployment with PSDeploy, the importance of abstraction, and a bit on how and why to write and publish PowerShell modules.
It’s time to combine these ingredients with a quick, real-world walk through on automatically publishing your PowerShell modules to the PowerShell Gallery.  If you want a full run-down showing how to deploy PSDeploy with PSDeploy, hit the link; otherwise, we’ll pick up the PSStackExchange module where we left off, and drop in some continuous integration and deployment goodness!

msorens
PowerShell for Admins

Every pithy witticism begins with quotation marks

“To be or not to be”. Without getting into a debate over whether Shakespeare was musing about being a logician, suffice to say that in writing prose, the rules of when and how to use quotation marks are relatively clear. In PowerShell, not so much. Sure, there is an about_Quoting_Rules documentation page, and that is a good place to start, but that barely covers half the topic. It assumes you need quotes and then helps you appreciate some of the factors to consider when choosing single quotes or double quotes.
But do you need quotes? Remember PowerShell is a shell/command language so “obviously” you can do things like this:

pscookiemonster
PowerShell for Admins

Finding PowerShell Sessions At Conferences and Events

The Current State

So! If you visit the PowerShell.org events page, you’ll find a bevy of PowerShell-focused events, from local PowerShell user groups to global PowerShell conferences.
What you won’t find, yet, is a list of PowerShell related sessions at the many other conferences and user groups you might consider attending.
Maybe you’d like to find PowerShell oriented sessions at non-PowerShell user groups and mini conferences like SQL Saturdays, VMUGs, Azure User Groups, Security BSides, DevOpsDays, etc.  These are great small events that can build your knowledge, help you meet local folks in a particular field, and often provide provide you with some free food.
Beyond these, there are plenty of summits and conferences that have a strong PowerShell track, or even just a handful of awesome PowerShell sessions, that might be worth knowing about. LISA, DerbyCon, MMS, WinOps, TechMentor, and many more.
How do you find these events?  There isn’t a solid option today, but hopefully we can change that.  Before we go further though, why is this even helpful?

Graham Beer
PowerShell for Admins

To ping or not to ping..The PowerShell way

As this is my first blog here, here’s a bit about me. I’m a current lead SCCM Admin in the UK, and have found this great enjoyment for PowerShell in the last 18 months. I’ve started my own blog, http://www.get-configmgr-content.co.uk/, to share my passion. The chance to blog on Powershell.org was too exciting not to do!
The inspiration for this blog came from a forum post on Powershell.org that I helped contributed on. The question asked was, how to display the name of failed ping, i.e. $computer is offline.
There were some great responses, the one I most liked which I slightly amended into a function was:

msorens
PowerShell for Admins

Complete Guide to PowerShell Punctuation

Quick as you can, can you explain what each of these different parentheses-, brace-, and bracket-laden expressions does?

${save-items} ${C:tmp.txt} $($x=1;$y=2;$x;$y) (1,2,3 -join '*') (8 + 4)/2 $hashTable.ContainsKey($x) @(1) @{abc='hello'} {param($color="red"); "color=$color"} $hash['blue'] [Regex]::Escape($x) [int]"5.2" When you’re reading someone else’s PowerShell code, you will come across many of these constructs, and more. And you know how challenging it can be to search for punctuation on the web (symbolhound.com not withstanding) !
That is why I put together a reference chart containing all of PowerShell’s symbology on one page. making it much easier when you need to look up a PowerShell symbol as you read code–or to browse for the right construct when you are writing code.
PowerShell Punctuation wall chart
Download the Complete Guide to PowerShell Punctuation wallchart from here.

Don Jones
PowerShell for Admins

My DevOps (DSC) Camp Detailed Agenda

If you’re deep into DSC and delving into DevOps, then my summer “Camp” event is probably meant for you - and now there’s a detailed agenda, overall agenda, and full event brochure. This is a really limited event - under 20, including product team participants, and we’re down to just a few seats left.

DevOps and DSC Camp Detailed Agenda