Despite its lack of features and options, PowerShell ISE used to be the primary tool to develop and edit PowerShell Scripts. It offered an integrated development environment (IDE) that included some basic features to build scripts and modules.
Microsoft is no longer actively developing the PowerShell Integrated Scripting Environment (ISE) and is being replaced by the more powerful and versatile open source Visual Studio Code (VS Code). With its ever-expanding options and extensions, VS Code is quickly becoming the new standard tool for developing not only PowerShell, but just about any other language you choose.
Despite all the new features available in VS Code, leaving the familiar environment of PowerShell ISE is difficult. It is like watching your child go to college. You are proud of the achievement but sad about having left a comfortable environment.
VS Code can be intimidating at first. As the default settings of VS Code can be a little hard to work with if you are used to working with PowerShell ISE. However, it’s highly customizable, and with the addition of Extensions and a few configuration settings, you can make VS Code look and behave just like PowerShell ISE.
To get VS Code to look like PowerShell ISE, the PowerShell Extension needs to be installed. To install, select the setting gear at the bottom left, then pick Extensions.
At the search box, type in Powershell and then install. This extension adds a few features to the default settings of VS Code.
To get the distinctive look of PowerShell ISE, select the settings gear and then Color Theme. Choose the PowerShell ISE theme.
Now that you have the look of PowerShell ISE, we need to set the behavior to match ISE.
The default install of VS Code lacks some features of PowerShell ISE, such as Zoom, Tab-Completion, Intellisense, and Code Snippets.
For setting the environment to match that of PowerShell ISE, we need to add some environment settings to the VS Code settings.
Keyboard and Mouse Actions
Open the command palette using the ctrl+Shift+P key combination. In the command palate box, enter “Preferences Open Settings (JSON).” This will open up a two-pane window with the user settings on the right. Insert the following code between the brackets on the right pane.
“Quote me as saying I was mis-quoted.” -Groucho Marx
There are two types of quotes that can be used in PowerShell. Single and Double quotations. Some critical differences between the two can make or break a script. Knowing these differences will make you a more effective PowerShell scriptwriter and help you avoid a rather simple mistake.
In this post, I’ll quickly explain these differences and provide examples of each scenario.
Single quotation strings are what you will most often use and encounter when creating or troubleshooting PowerShell scripts.
Consider the following example:
# Assign a variable with a literal value of 'single'.
# Put the variable into another literal string value.
Write-Host-Message'Fun with $MyVar1 quotes.'
Now examine the output:
In the above case, PowerShell ignores
$MyVar1 and treats the variable literally as $MyVar1, exactly what was typed. There is no substitution here.
But how do you get PowerShell to recognize the variable value within a quoted string value? That’s where double quotation comes in.
Double quotation gives you a dynamic element to string values. You will encounter this type of string quotation when the string contains dynamic data from variables stored in memory or dynamically generated.
Consider the following example:
# Same as previous example. Create a variable with a simple value.
# Now to demonstrate double quotes magical power of interpretation!
Write-Host-Message"Fun with $MyVar2 quotes."
Now examine the output:
In the above case, PowerShell processes
$MyVar2 because it was enclosed by a double-quoted string. Double quotes make PowerShell parse for text (the variable) preceded by a dollar sign and substitutes the variable name the corresponding value.
Real World Scenario
Now, apply this knowledge to a real scenario. Let’s say that you need to create a small function that will give an operator on your team some real basic information:
Date / Time
Disk % Used
Disk % free
You need to return this information visually to an operator. Simple.
First, some pseudo code. We need to display the date time as today’s date and time. Think about how this string value will work. We can use
Get-Date and the
-Uformat parameter to give us the required date/time by using the correct patterns:
$date=Get-Date-UFormat"%m / %d / %Y:"
Testing the code in a PowerShell terminal confirms this works:
That takes care of the first part of the script. Now, I need to gather some disk information to also output to the terminal. The key metric I’m looking for is the percentage of free space remaining. I’ll display this information using
Write-Host again, but this time I’ll need to insert additional code inside the double-quoted string. Remember, this information will be dynamic. For the purposes of this example, I’m going to create a variable, then utilize an available member type property to get the value I’m looking for:
Testing the code in a PowerShell terminal confirms this works:
Perfect. We now have two variables that we can place in the strings that the operator will see when running this function. So let’s assemble the bits into the final script that will become our function:
Write-Host-ForegroundColorYellow"There is $($disk.PercentFree)% total disk space remaining."
Testing again in a PowerShell terminal, here is what the operator would see:
Notice what I did inside the last
Write-Host line with the
$disk variable. PowerShell evaluates the $( ) construct as an entire subexpression then replaces the result. Doing it this way also helps you avoid having to create more variables, which saves memory and can even make your script faster.
The function still needs some work. So let’s finish it off by adding some math to show a full calculation to the operator:
Write-Host-ForegroundColorRed"There is $(100 - $disk.PercentFree)% total disk utilization on drive $($disk.Name)."
Write-Host-ForegroundColorYellow"There is $($disk.PercentFree)% total disk space remaining."
The operator can now make some faster decisions while supporting a remote system by using this function.
There’s not much to quotes in PowerShell. The one key concept to remember is that you need to know when to be literal ( ‘ ‘ ), and when to be dynamic ( ” ” ). By default, you should always use single quotes unless there is a requirement for dynamic data in the string construct. I hope you found this information useful!
“Distrust and caution are the parents of security.” -Benjamin Franklin
If you’ve ever deployed Windows Updates to clients on your network, you have probably been asked by your manager(s) what KB’s were deployed, and when if an issue comes up on a workstation or server. Unfortunately, sometimes the built-in WSUS reporting tool can leave you frustrated and doesn’t have great functionality for generating them outside of the WSUS management GUI. A problem I regularly encounter is a crashing MMC, which then crashes the WSUS services, causing me to have to reset the node and start over. It’s very annoying.
Distrust & Caution
I was recently asked by a group of managers that were working on validating a security vulnerability scan for some assistance. This vulnerability scan was claiming that a set of systems were missing particular Microsoft KB’s, KB’s that were recently approved, deadlined, and showing as installed in the WSUS management console. I sent some screenshots of the console status along with my sysadmin reply. I didn’t give it much thought at the time because I was busy with other projects and this was a routine request.
A day or so went by, and another vulnerability scan was run, producing the same results. Management was not convinced that the updates were installed. Having issues with WSUS from time to time, I started to distrust the built in reports and the management console. To be cautious, and a little more diligent, I decided to bypass the WSUS management console and go straight to the workstations and servers that were showing up in the security vulnerability scan.
Some Explicit Remoting Here, A Couple of Cmdlets There….
Luckily, the security vulnerability scan only found about 4 workstations and 12 servers with these supposedly missing KB’s. So I created a simple list in a text file using the Fully Qualified Domain Name (FQDN) of each host. I also knew for a fact, that the missing KB’s would have been installed in the past 30 days as I just completed a maintenance cycle.
With this knowledge in hand, I jotted down some pseudo code to help me begin. Here’s what I outlined:
Store my text file that contains the list of hosts.
For each of the hosts in that file, run a command.
The command must gather installed KB’s installed in the last 30 days.
The output only needs to contain the hostname, KB/HotFix ID, and the install date.
The output needs to be readable, and just needs to be a simple file.
No fancy coding needed, just comparing visually to what WSUS reporting was displaying.
Based on my notes, I had a good idea of what I was looking for and what cmdlets I might need. The primary focus was on the
Get-HotFix cmdlet. What this cmdlet does is query all the hotfixes (more commonly referred to as security updates) that have been applied to a Windows host. You can read more about this cmdlet and how to use it here.
Get-HotFix does not support implicit remoting so I needed to come up with method to run this cmdlet on the systems I needed to report on.
Invoke-Command does and you can pass multiple values to the
-ComputerName parameter. I already have saved a list of hosts I am targeting, so I’ll save myself some typing and store those hosts as a variable. To do so, I’ll have to assign a variable name and make the value the list of hosts.
Get-Content will read the content of the text file line by line creating an array of sorts. Let’s call this array
$Hosts . Now I have a command, some data to feed to the next set of commands, but I need to make the resulting data readable and concise.
I want to take a moment here to emphasize “Filter First, Format Last.”. Remembering this will help you when working with these types of scripts. Now, running the
Get-Hotfix cmdlet by itself will typically result in a long list of updates that have been applied to a host. Filtering helps gather just the information you need. Without filtered data, formatting is useless at this point. Think of filtering as your data type requirements, and formatting as how you want that data displayed. For my purposes, I already had the requirements thought out. I needed to get updates installed in the past 30 days.
To filter, I will need to use the
Where-Object cmdlet and then pass along some member properties and comparison operators with a dash of math. To do this, my pseudo code will take every object returned (
Where-Object-Property installed on data is greater than (
-gt)today’s date (or whenever I run the script) minus (-30) days ago. That will get the initial data I’m looking for but I want to filter the returned objects and their properties a little more. This is where
Select-Object will help, allowing me to further trim the amount of data to be displayed to just a couple of crucial properties.
Now that I have the data properly filtered, now I can move on to formatting the results into a usable format. To do so I’ll pipe ( | ) the results from my previous filtering to
Format-Table-Autosize and output as a file type of my choosing. I’ll need to use
-ErrorActionSilentlyContinue parameters to ensure that each result is written to the next line in the output file and if an error occurs, it won’t cause the rest of the hosts to not be contacted.
I chose to go with a text file because I didn’t require anything fancy. You can change the output to meet your needs. My output looked something similar to this:
As a mentor, I’m often asked, “How do you get inspiration for a PowerShell script?”, followed by something sounding similar to, “I just don’t know what I can script or where to start.” When I’m told that, the person saying it sounds defeated and about to give up. This was a question & feeling I had myself early in my PowerShell journey too.
“So, what’s the answer, Bill?” you might ask. Well…the answer you seek, young grasshopper is…
How I Started
Let’s talk about how I started to approach scenarios and challenges by using existing documentation as my base of reference, or pseudo code. Many years ago, I struggled to make scripts. No matter the language, it was an awful feeling of imposter syndrome. I could read some code and stumble around clumsily figuring out some bits here and there, but it was a constant struggle. It wasn’t until I started documenting my IT processes that I began to correlate written word to small bits of pseudo code that I could then translate in to PowerShell one-liners. Once I started doing that, things got a lot easier.
I have some maintenance tasks that I have to perform at least twice a month for User Acceptance Testing (UAT), Quality Assurance (QA) and production environments. Lucky for me, these tasks are already written down and stored in a team KB article. With half the battle already won, I carefully read through the documented steps for taking systems and applications down gracefully for maintenance. The tasks progresses something like this:
Place monitoring agents in maintenance mode (nothing like getting email alerts for known issues)
Stop IIS application pools 1,2 & 3 on X server
Stop IIS application pool 4 on Y server
Stop services on A,B,C & D servers
Log into WSUS, approve & deadline OS updates to specific groups
Allow reboots to occur.
Looks pretty straight forward right? My predecessors were manually performing these steps for years. Well, I’m not my predecessors. There’s enough information here to begin making a script. Let’s begin.
Task 1 could be automated, but for the purposes of this post I’m skipping it because not all monitoring platforms are the same. Moving on.
Task 2. Now we have something to work with. Using key words, I begin by discovering what commands I have available that might stop an IIS application pool:
Stop-WebAppPool Appears to be exactly what I need to complete this task. Spend a minute or two reading the help if it’s the first time you’ve seen this cmdlet:Get-HelpStop-WebAppPool-Online
Now I know how to tackle Task 2andTask 3. My code now looks like this:
Stopping IIS Application Pools Example
On to Task 4. Now this one should be simple for anyone who is new to PowerShell, as it’s a common task that is demonstrated in a lot of training material. This task will make use of the
Stop-Service cmdlet. There are a few ways this can be done, but I’ll keep it simple for now so we don’t get into the weeds and detract from the overall goal.
On each host, there are two services that work concert with each other as part of an application that was hosted on the IIS servers in Tasks 2 & 3.
Stop-Service will allow us to enter multiple values in the
-ComputerName parameter, and since the naming scheme I’m using is short, it’s not a big deal to enter them all here. I’ll also be using the
-ServiceName parameter, which also accepts multiple string values. When finished assembling the code, it looks like this:
Stopping Multiple Services on Multiple Computers Example
Stop-Service-ComputerName'A','B','C','D'`#yup I used a backtick here
Great! I’ve just saved a few minutes of not having to RDP to each of these systems, or use Server Manager, or type this all out in a PowerShell terminal.
Let’s Add More Stuff!
The whole reason for shutting all these services down gracefully is to be able to apply Windows security patches to the server OS without screwing up the applications if they were still being used during a scheduled maintenance window (humor me for a moment and save the snark about Windows Updates).
Enter PoshWSUS. This handy PowerShell module contains exactly what I need for the final component in my scripted task. There are a lot of cmdlets available in this module and I’m not going to explain all of them right now.
In order to complete the last step, I need to:
Connect to my WSUS server. Connect-PSWSUSServer-WsusServerlocalhost-Port8530-Verbose
Store the KB’s to be deployed as a variable. $Updates=Get-Content'C:\PScripts\Maintenance\updates.txt'
Store a deadline of 1 hour ahead of the time the script executes as a variable. $Deadline=(get-date).addHours(1)
Get updates, approve then set install flag along with the deadline flag to assigned groups.
As you’ll see above, I’ve thought out the logical steps and created some pseudo code to get started. It’s the same process you’ll follow when trying to create your own scripts. It’s almost as if there’s a theme developing here!
Now on to what you’ve been waiting for. Let’s assemble all the bits into the final script:
This script will perform documented tasks that
were once done manually.
# I like to place variables at the top of the script to
# make it easy to change them without digging through the
# Clean up, pick up, put away. Clean up, everyday!
The key thing to remember here is, if you can write it down, you probably can script it. So go back and look at some of your documented processes and procedures, and you’ll soon discover that you’ll have enough inspiration to keep you busy for a while making PowerShell scripts.
If you’ve read my past blog post on “How I Learned Pester by Building a Domain Controller Infrastructure Test”, it should be pretty obvious that I’m a fan and love using Pester now. I even build small tests for small scripts like the one above.
I need to a quick test with some visual output since I’m typically running this script from a PowerShell terminal manually. So, with the same pseudo code used earlier, let’s build a simple test that will verify all the actions in our script did what we expected:
Basic Pester Test for My-MaintenanceTask.ps1 Example
I left out tests for servers B,C & D because they would be identical to the test shown for server A in the above example. Now all that is required to run the this test as part of the
My-MaintenanceTask.ps1 script would be to add this line at the end of that script:
After the birth of my first son, I was feeling like I was at a crossroads in my career. I have been working in IT on my own and for many others for a while now (I built my first computer somewhere around 1999-2000) and have been exposed to many different types of environments and tasks. Since his arrival into my life, I have had a growing sense of responsibility to move beyond just having mentors, to being the mentor and teaching; from being the apprentice to becoming the master.
Back in May, I was following quite a few industry peers who were tech bloggers, presenters, and evangelists. One of those peers is Adam Bertram. I had seen a few tweets about an opportunity to get involved in a new venture that centered on the IT pro and career advancement. Having just finished reading the book “Be The Master” by Don Jones, I was inspired to take a leap and do more, I just wasn’t sure exactly how. I responded to one of Adam’s messages. Not long after, I had received a message from him. He explained that he was developing a new business in which IT pros could gain some valuable exposure to the IT community, teach others and further their careers. Everyone had something worth teaching.
I left that conversation having been inspired and was convinced that this was an opportunity worthy of investing time in. Therefore, I began to think of something that I knew that I could teach. Having some experience with Group Policy, and a passion for PowerShell, I did something…
I Just Hit Record…
It sounds easy, and for the most part that is true. For many people, including myself, not so much. IT pros tend to be a little shy, and afraid to put themselves out there. Aside from occasionally being very active on some forums, I had never recorded myself. I have taught some people one on one, but never a group of random strangers on the Internet.
This was an undiscovered country for me.
To Boldly Go…
After a period of reflection on what I could possibly contribute that was in my mind worthy of teaching. Side note, everything is worth teaching! Not everyone who is in IT is at the same point in his or her career as you. I remember having a hard time with some topics and not having someone there to teach me, but I digress.
I searched my geek stash for any supplies I could find to aid in making a recording. A spare monitor here, a junk microphone there. Some free screen-recording software. With zero initial budget, there were some struggles. Specifically audio battles. With the help of @MichaelBender, I obtained a much more high-quality microphone that eliminated most of the poor sound quality that was keeping my demo from passing acceptance to become a snip contributor. I am forever grateful for that random act of kindness.
With newfound confidence and better audio, I regrouped and submitted another demo, and it was accepted. The first hurdle passed, I learned a lot and was inspired to keep going. So I made a short snip on How to Create a Starter Group Policy Object with PowerShell on Windows Server 2016 which demonstrates how to quickly create an empty Starter GPO that can be configured with baseline settings, creating a template of sorts for future use. With some guidance from Adam, @_BryceMcDonald and the TechSnips editing team, the final snip was polished and published. It was a milestone for my career:
I was now a professionally published contributor.
The feeling of knowing that I have left something valuable for someone to learn from has not faded. It’s driven me to also submit writings about Pester to the TechSnips.io blog, and to publish two additional snips since then with more in the works as time allows. I take great pride in telling people about what TechSnips has done for me and why my fellow IT pros should consider joining. We all have something worthy of teaching the next generation of IT pro. We all need to “Be the Master.” Help someone else. Just hit record, and see where it takes you.
Two things I get paid to do, solve problems and learn new stuff.
I am fortunate to know very early that I wanted to work with computers. The only problem was I could not concentrate long enough to complete a formal school course.
I was kicked out of two community colleges for academic suspension. I tried to take the required courses like history, calculus, economics etc… but I got bored and never did the required homework or study.
It All Started in the Navy
I eventually ended up in the Navy. I signed up for an extra year to get the technical training I wanted. It was perfect. 8 hours a day 5 days a week for a year. Straight electronics. Resistors, capacitors and circuit boards, Oh My!
The best part? I was given a box of parts and spent 3 months putting it together to build a radio. If it worked, I passed, if not I failed. ( Hint: I passed)
Oh and the discipline, self-esteem and doing things I never thought I could do turned a manchild into a proud, self-confident man. The Navy instilled in me the self- discipline I was sorely lacking.
My Consultant Years
I became an IT consultant right out of the Navy. My lack of a formal degree was an obstacle at times but I never said no to a problem. I knew I could solve any problem thrown at me. After all, I just spent 6 years in the Navy doing just that.
My love of learning also kept up to speed on technology. Two hours every night either on a self-study course or learning a new technology that had just come out.
My first network security job even had me build my own Linux PC on the first day. Back then it was a very manual process with a lot of compiling. If you ever built a Linux PC using “Linux From Scratch” you will know what I mean. I learned a lot and I loved it.
A lot of what I learned did not immediately apply to my job. For example, I am not a programmer but I learned how to use Git just because I thought it was cool. It was the same for a lot of technology I learned. This lifelong learning kept me employed.
How did I arrive at TechSnips?
Well, after many years of IT consulting, it is getting a little uncomfortable being the oldest tech on the IT team. I have been asked in more than one interview why am I not an IT Manager or have some supervisory experience. Yes, age discrimination is a thing.
You know what IT managers do? Answer phones, create budgets, develop strategic plans that no one will use, use words like “Synergy”, “heterogeneous” and “teamwork”. No, I need to be in front of a keyboard. I can make servers dance, sing and do your dishes.
So while my peers were getting management jobs, I was designing networks for data centers, installing hundreds of servers, laying out cabling, and learning to break into systems. I was good at it
I had been looking for something that I could do remotely and still generate income. I do have a family to support. I started (and failed) at several blogs. I realized that I did not have the business acumen to make it successful.
Feeding My ADHD
This is where TechSnips comes in. I actually came across Techsnips from a tweet posting about a snip for a problem that had. I watched the snip and it leads me to a solution that I needed.
I had been working from home for a while now and I was not looking to go back to the office again. I wondered if they were hiring and, even better, if they were hiring remote techs. I navigated to the contributor page and immediately knew I had to apply.
The more I read about the contributor role, the more excited I became. I was hesitant to submit a video audition (the presenter role), but Anthony Howell said it did not matter. Produce a snip and let me see what you got.
The format of producing a snip fed very well into my ADHD. Short, technical videos on a specific topic that I am interested in. If I get bored with a topic, choose another topic or suggest one. Each Snip was to be no more than 15 minutes. I thought this was perfect. I could do this.
So, I produced my first snip and it was accepted. a couple of days later, I got a call from Anthony Howell welcoming me to the team. The more I heard about what TechSnips is all about, the more excited I became and I knew I had made the right decision.
So, today, I am a producer of several snips and have many more in the works. Producing snips also has given me the confidence to improve my presenting skills.
I am not used to talking in front of people or teaching online. The team at TechSnips has provided valuable advice on how to present technical videos and engage an audience.
TechSnips is giving me the opportunity to not only do what I love but actually get paid to do it.
Do you ever sit back and look at the path you took in life and wonder how you ever managed to get to where you are? I sure do. Like every day. I’m currently involved heavily with TechSnips, but I sure wouldn’t be here if I hadn’t started getting into the twittersphere back in April, and I sure wouldn’t have been there if I hadn’t made it to the PowerShell Summit this year, and I sure wouldn’t have been there if a spot hadn’t opened up, and I sure wouldn’t have been there if I didn’t decide to start dictating my own career this year, and well, I’ll stop there.
2018 was not going to be an exciting year for me. I had a steady low stress job that paid me my worth, but worked me like an IT pro with half my experience. So I ended up being paid more than ever, but after a leadership change, I was also stuck answering more phone calls than ever, even compared to my short stint in a Geek Squad call center. I initially decided that the pay plus benefits were too good to walk away from, but like any independent spirit, I always asked myself: What would this look like if I were calling the shots?
From a reminiscent standpoint, I see that my career was treading water. In our industry, you might as well just call the lifeguard if you are content treading water. I, fortunately, was not. I requested to go to the PowerShell Summit, but that request was rejected. And so, in a move that was unprecedented in my career, I made the call to request PTO for that week and take myself. The problem? I missed registration by 3 days.
I dutifully put myself on the waiting list even after reading the statement about how the waiting list is rarely utilized. Kind of like the old ‘we’ll keep your resume on file in case something comes up’. A fun fact about me is that I live within driving distance of Bellevue and I decided to share this information with Don Jones in case something came up. He promised that if something came up last minute, that I would be the first to know. And, I’m sure you saw this coming, but a last minute opening did arise and within 15 minutes of receiving the notification via email, I was a registered attendee for the PowerShell Summit 2018, my first conference ever.
Due to the situation mentioned previously, I decided to put in my notice for my day job the week before the PowerShell Summit with the intention of going out on my own as a consultant. I had no clients, no plan, and no consulting experience, but I had a dream that I was prepared to burn through my savings trying to achieve.
Without venturing too far out of scope here, the PowerShell Summit was career changing for me, literally the best $2000 (admission + expenses) I’ve ever spent. If I hadn’t already put in my notice, I definitely would have the moment I got back, though by that point I didn’t have a job to come back to, not that I shed any tears over that.
While I was at the Summit, I realized just how much a topic like PowerShell thrives in it’s community. Heck, I sat in on Adam Bertram’s side session on how blogging increased his income two-fold because of how attracted a knowledge sharing expert is to some businesses. One of his pieces of advice was to be active in the community, so I decided to take that to heart, and thus The PoSh Wolf was born.
After I got back from the Summit, I made my first tweet ever. Within two weeks I had a blog up and running and I even managed to make my first pull request on a GIT repository, specifically a simple typo fix in the README for PlatyPS. It wasn’t anything major, but it was a start. I had finally put myself in the position that I could start giving back to the community and it felt good.
How I found TechSnips
It wasn’t long after that I responded to Adam’s tweet for content producers. TechSnips was looking for folks interested in sharing knowledge in snip format, an unproven how-to style. I didn’t realize it at the time, but this is revolutionary when compared to the rest of the technical training landscape. In a 3 minute snip, we can walk someone through how to create a LightSail VM in AWS and you don’t even need to know what AWS stands for! You’ll never want to sit through a full AWS course after one of those videos.
The nerve-racking part about applying to be a contributor is the audition process. You have to pick a topic and demonstrate your skills. For someone like me, this was tough! I felt like an imposter. Sure I had 8 years of IT experience, but when put on the spot, it didn’t feel like it. If you want a laugh, check out my audition video (https://youtu.be/NYkZpE_IDjs). Its obvious why it was never published. It was terrible! But, after practice and some good feedback from the peer reviewing stage in our pipeline, I’ve gone from being a shy imposter to a confident presenter. This has made me realize that the only difference between the well-known content producers and the rest of us is that they choose to share their experience. For the most part, they aren’t stuck up jerks, they are just IT pros that are happy to share their knowledge.
Why I’m still here
Beyond the concise format, one of the things I really like about TechSnips is that they’ve fostered a community of like-minded IT professionals that are passionate about sharing their knowledge. These folks stick around because TechSnips has an amazingly efficient publishing pipeline that removes most barriers between an experienced expert and a polished how-to video. And this process improves as fast as you can make recommendations. After working in financial IT, I can verify that this level of nimbleness in a platform is insane.
Now, before you asked about this ‘efficient publishing pipeline’, let me ask you this: Have you ever tried to produce a training for YouTube or somewhere else? It takes a TON of time. Preparation, recording, editing, and finally publishing. Well, TechSnips takes care of the editing and publishing for all of their snips. This means that I, as a contributor, just need to hit record and walk the viewer through a how-to and the editors go back and add the flashy title, the highlights, and remove my mistakes. So, after having a few snips under my belt, I can submit a snip in an hour or two, depending on the depth of content. Then it gets published after some review and the editing process. It is that simple and that is what I love about it. You can keep putting off learning Adobe Premiere and focus on snipping.
One thing I scoffed at when I initially joined up was TechSnips calling itself a ‘Career Development’ platform. They are obviously just using that as a marketing gimmick to attract interest, right? But do you think improving your confidence develops your career? Or maybe having a portfolio of snips would look good on your resume? It sure looks good one mine.
Embracing DevOps means being able to manage different platforms and OS’s and learning different shell scripting programs maintain them. With PowerShell Core, you write once, deploy everywhere. It’s another tool in your toolbox.
SharePoint farm configurations are notoriously difficult in not only documenting accurately but also migrating those configurations to a new SharePoint farm.
Commercial tools and utilities help, but each tool has its pluses and minuses and some of them are not effective and often buggy. Additionally, the tools can be expensive and come with a high learning curve.
SharePointDSC.Reverse is a script developed by Nik Charlebois that utilizes SharePoint DSC resources to gather detailed information about the farm and outputs into a configuration file that can be consumed by PowerShell DSC and SharePointDSC resources.
The resulting PowerShell DSC configuration files can be used to create a near perfect copy of the farm to replicate in the new environment or can be used as a template for Azure automation.
SharePointDsc.Reverse currently supports SharePoint Server 2013/ 2016 and soon SharePoint 2019, running on Windows Server 2008 R2, Windows Server 2012 or Windows Server 2012 R2 or higher.
There are a few prerequisites before running the script. PowerShell v 5.1 is required. Two PowerShell DSC modules are also required and will need to be installed.
Log into the Central Administration server and open a PowerShell session as administrator. The SharePointDSC reverse script is installed with a similar command but using a script instead of module. To install the SharePoint Reverse script, we’ll use
How To Use
Now that we have all the necessary modules installed, it’s fairly easy to use. To start the process, enter sharepointdsc.reverse.
As the script runs, it asks for the credentials for the various managed accounts. Using the DSC resource provided by SharePointDSC, the script performs a detailed scan of the farm, gathering all the settings and configurations.
For a large farm, this will take several minutes to complete. Once it’s complete, It prompts for a directory to save the results. the resulting files can be consumed by SharePointDSC.
To validate the configuration, compile the spfarmconfig.ps1 file to create the .mof resources.
The resulting files from SharePointDSC.reverse can be used to duplicate the SharePoint farm in different environments, on-premises or in the cloud. The configuration file, the error log, and the environment data file, all contain detailed configuration settings of the farm. Custom solutions (.wsp files) are copied into the directory as well.
Duplicating the SharePoint farm
SPFarmConfig.ps1 file can also be uploaded to Azure Automation to duplicate farm configurations for your Azure based SharePoint farm. To duplicate the SharePoint farm in a new environment, apply the configuration to the farm by starting the DSC configuration.
In a multi-node farm, the configurationdata.ps1 file already has the node names, roles, and services that are running on each server in the farm. The file is formatted very similar to JSON and editing this file for the new environment can easily be completed using Visual Studio Code.
The spfarmconfig.ps1 file has the detailed farm configuration and also lists products installed and version numbers. It will also have details about each web application, site collection, and farms settings. Patches applied and version numbers of products installed are also displayed.
One additional benefit of these files is that they can be part of a disaster recovery plan. Restoring the farm from a complete loss can now be accomplished in hours instead of days.
Terraform enables you to create, change and improve infrastructure reliably and predictably. It is open source and lets you create declarative configuration files that can be treated as code, (Infrastructure As Code). In this article, we are going to step through the process to create an EC2 instance using Terraform.
Next, we then create an IAM account in AWS. This will be needed so that we can use it within the Terraform code, but not quite within the code. That would be reckless! We can create a local profile which will let Terraform read those credentials, but not include them in the actual code so that the code can be stored and shared safely.
Next, we are required to define our resources. We define the Amazon marketplace image (AMI) that we will use. Please check the ID for your region as this can differ from region to region. If you follow along with this code, there will be no need to update. We have selected a Windows 2016 image to use in this case.
At this stage we are ready to apply the configuration, however, Terraform will need the AWS plugin and will also need to initialize the Terraform environment. We use the command terraform init
Now you can see from the screenshot, we have the AWS plugin and some more information regarding the environment.
So now we are ready to execute the configuration and create our instance. Terraform will use the command ‘Apply’ to execute this, and you are advised on what actual configuration will be executed. At this point, you have not actually run anything. (In earlier versions you would have used Terraform plan to view the configuration that is to be implemented).
By typing yes, this configuration will now be sent to AWS, you can see it’s now ‘creating’.
If we switch over to the Amazon console we can see the instance, this few lines of code demonstrate how powerful and easily infrastructure can be created using Terraform.
Search by the tag we set in the Terraform configuration file.
Use terraform show to view the configuration changes. This is a very rich output that gives you detail on all aspects of the resources you have created.
It is also just as easy to remove your configuration using the terraform destroy command. You must be careful with this command as it will analyze any Terraform scripts it finds in the same directory as candidates for removal.
Let’s run terraform destroy.
We now type ‘yes’
Back in the AWS console, we can see that the instance has been terminated.
I hope this article has given you some insight into how powerful Terraform is and how easy it is to get a basic configuration up and running!