Pscookiemonster

Explore articles and content from this author

Pscookiemonster

22 articles published

1 min read

Slack and PowerShell

Having a platform that enables ChatOps can be a game changer.  You can quickly see changes, alerts, build status, discussions, emergency chats, and more, all in a single, searchable interface.  If you can sift through the gifs.
Bots are a hot topic these days, and and it’s well worth checking out Matt Hodgkins bit on integrating PowerShell with Hubot.  Bots are a great alternative to trying to spin up a web front end for PowerShell.
On top of bots, systems like Slack often offer a wealth of integrations, allowing you to hook into systems like Nagios, PagerDuty, GitHub, Trello, and many others.
Occasionally, you might have something that doesn’t integrate natively.  Maybe you want to integrate Slack messages into your SCOM command notification channel, your CI/CD build process, orchestration system, configuration management systems, or even ad hoc scripts.
If you’re using Slack, check out the Slack API methods, or an incoming webhook.  With the API in particular, you can do some handy stuff!
If you like the idea of re-usable tools and abstraction, check out PSSlack, a PowerShell module that we’re starting to build out, which can simplify sending messages, searching messages, and more.
pslack

2 min read

I'm Not A Developer

Are you intimidated by scripting? Does PowerShell seem too much like programming to you? You aren’t a developer, why should you learn this mumbo jumbo?
It turns out, PowerShell is quite easy to get started with. Can you run ipconfig? Do you know how to give someone instructions? You could probably pick up the PowerShell basics in a month of lunches or so.
Don’t believe me? I spent a few minutes to compare a simple task in four languages. PowerShell is a single, easy to understand command. Python is two lines and starts to include some syntax like .().
We won’t even look at the C example here, but check out this C# code that simply reads and prints out the content of a file:

1 min read

Finding Evil LDAP Queries

Have you ever wondered what LDAP queries were hitting your domain controllers? Even outside of fun investigations, it can be insightful to get a sampling of queries hitting your domain controller. The more services you have integrated with Active Directory, the more likely a vendor or sysadmin unwittingly configured their service to produce evil queries.

Mark Morowczynski from Microsoft wrote a great post on finding these expensive, inefficient, or long running queries - But something was missing. Screen shots of regedit? If you have more than a handful of domain controllers, enabling and disabling this logging is going to be quite a chore.

2 min read

Writing and Publishing PowerShell Modules

Earlier in August we mentioned that modularity and abstraction are quite helpful. PowerShell modules can help enable these concepts.

You might ask “Modules… why can’t I just write a function?” There are a number of benefits to bundling your functions into modules:

  • Simplify code organization
  • Group related functions together
  • Share state between functions, but not with the user
  • Re-use “helper functions” that you don’t want exposed to the user
  • Improve discoverability: Find-Module MyModuleGet-Command -Module MyModule * Simplify distribution: Install-Module MyModule `Where does that last bullet come from?

If you’ve worked with Perl, you’ve probably used CPAN, which archives more than 150,000 modules. Other languages have similar tools, like PyPI for Python, or RubyGems for Ruby.

2 min read

Abstraction and Configuration Data

Modularity and abstraction are a huge benefit in scripting and coding. Which of the following blocks of code are easier to understand?

$SQLConnection = New-Object System.Data.SqlClient.SQLConnection $SQLConnection.ConnectionString = 'Server=SqlServer1;Database=MyDB;Integrated Security=True;Connect Timeout=15' $cmd = New-Object system.Data.SqlClient.SqlCommand("SELECT * FROM Table1",$SQLConnection) $ds = New-Object system.Data.DataSet $da = New-Object system.Data.SqlClient.SqlDataAdapter($cmd) [void]$da.fill($ds) $SQLConnection.Close() $ds.Tables[0] Or…

# Invoke-Sqlcmd2 -ServerInstance SQLServer1 -Database MyDB -Query 'SELECT * FROM Table1' If you aren’t a masochist, the latter probably looks a bit nicer. Oh, and it offers other parameters, error handling, parameterized SQL queries, built in help, and other benefits the .NET code block misses.

5 min read

Continuous Integration, Continuous Delivery, and PSDeploy

Are you starting to use version control at work? Are you being pestered by fellow PowerShell aficionados to start learning version control? Did you catch the PowerShell.org Crash Course in Version Control and pick up some Git and GitHub experience? Shameless plug, sorry : )

Version control is just the start. What if we want to automate testing? To deploy our files, folders, and other artifacts out to production or other environments? Version control alone offers some nice benefits, but without these extra steps, it might introduce some pain points!

1 min read

RabbitMQ and PowerShell

Have you ever needed to communicate between scripts, perhaps running on different servers and in different languages?  Did you use a non-standard “messaging” solution like the file system or a SQL database? Did you try to avoid this and squeeze everything into a monolithic, delicate script?

RabbitMQ is a solid messaging solution that happens to have a handy REST API and .NET client, which means we can use PowerShell!

Wrote a quick hit on setting up a simple RabbitMQ deployment and using PowerShell to manage the solution and send and receive messages. Thanks go to Mariusz Wojcik and Chris Duck for writing and sharing the PowerShell modules that were tweaked for this article.

1 min read

Decorating PowerShell Objects

Ever wonder how PowerShell seems to know how to format objects? When you run

Get-ChildItem or

Get-WmiObject , you only see a few key properties, but a wealth of other information is available through commands like

Select-Object and

Get-Member .

Have you ever written a PowerShell function that you nearly always pipe to

Format-Table ? Wouldn’t it be nice to specify some default properties and force them into a table?

Stop by for a quick hit on how to decorate your PowerShell objects with type names and formatting, including a re-usable tool to abstract out some of the details.

1 min read

Trust, but Verify

The PowerShell code you write can turn up in interesting places. Production services might rely on it. Your co-workers might take a peak and borrow ideas from it. You might decide to share it online. Someone might see your code online and use it in their own solutions.

Hit the link for a quick bit on how we can help create more reliable, consistent, and secure solutions. Simplified to one line: always ask yourself “what could go wrong?”

2 min read

Survey Results: Source Control for the IT Professional

First off - thank you to everyone who participated in the version control survey!
We’ve had a fun few weeks - Somehow the PowerShell Summit, Build, and Ignite were scheduled back-to-back-to-back. Among a host of other announcements and tidbits, we found that Microsoft has open sourced the DSC resources on GitHub, that Pester will be included in Windows, and saw a cool demonstration from Steven Murawski on using Test Kitchen to test DSC resources.
These and other solutions and technologies are starting to assume you know how to use source control, and many require having a source control solution in place - how do you automate testing and deployment on a commit, if you have nothing to commit to?
Source control has long been an important component of IT, but it seems IT professionals, particularly those in Microsoft environments, aren’t consistently using it.
You might expect a gap between IT professionals and developers, but less than 50% of IT pro respondents used source control as a team.

Breaking down the IT professional population by environment, we see that Microsoft environments are even further behind. Many PowerShell aficionados work on teams that aren’t using version control.

Long story short? IT professionals, management, and vendors have work to do; these new tools and ideas that rely on source control are great, but we need to work on finding a horse for the cart. The rest of my rambling analysis can be found here.
If you want to get up and running quickly, consider using GitHub for your PowerShell projects. You can start with the easy-to-use GUI client, and drop into the command line when you want to get your hands dirty. It’s a great way to start learning about source control, and to get involved in the community.
Do you have any suggestions on how we can get to a place where using source control is common place for IT professionals? Is this a worthwhile goal? Sound off in the comments!