Reset-Module ~ Something that’s been missing for a while.

I write a lot of little PowerShell Modules that I am constantly tinkering with. This forces me to reload those modules in my console windows constantly. For each module it’s three commands:


Remove-Module -Name RestPS

Update-Module -Name RestPS

Import-Module -Name RestPS

It’s Annoying!

So here is a simple function to take care of those commands with a single command!


Reset-Module -Name RestPS

The Function is available in the ‘jpsider’ module on the PowerShell Gallery.

If you have any issues, report them on GitHub.

Enjoy!

Folding@home – How you can help.

One thing I have learned over the past few years is that I really enjoy helping people out. With the current world events and everything I normally do in my day to day life (coaching soccer, volunteering at the children’s school, etc) canceled for the foreseeable future, it was nice to see that I have another way. Enter – Folding@home.

My wife was ecstatic when I told her that I was going to run upstairs and start folding. She was less enthused when she found out it was not going to be clothing.

Twitter has been blowing up the past few days about Folding@home, so I did some research and determined I can help! At a minimum, I knew I could use my VMware based homelab to throw cycles at the cause. I also reached out to the owner of my company, Belay Technologies, to see if we could use idle equipment in our lab. Sure enough, the answer was yes!

One thing I love about Belay Technologies is that we are always looking for ways to help.

Okay, Okay…  You may be wondering what Folding@home is. The answer is that it’s a distributed computing solution that is looking to solve scientific problems. It’s nerd stuff!

folding

Need more information on Folding@home, Check out their website. Review their FAQ.

What’s been the buzz on Twitter? Well, VMware decided to create a fling to make an appliance that is easy to deploy into vSphere and run Folding@home. Since it was VMware, I had to try it right?

Check out their blog post from the Office of the CTO.

It didn’t take long to get started.

  1. Visit the Fling Site and download the OVA.
  2. Review the PowerCLI script (cringe a little, it needs some TLC).
  3. Modify the PowerCLI script to work in my environment. 🙂
  4. Deploy the OVA to my homelab.
  5. Create a team for Belay Technologies.
  6. Deploy the OVA to the Belay Lab.

And now we are helping to save the world, without leaving the office.

folding01

Here is a quick snippet on how it works from the Folding@home website.

foldingworks

  • Team Numbers (To view stats)
    • VMware – 52737
    • BelayTech – 246789

Hopefully, you will take some time to consider helping the cause by donating your unused CPU cycles.

READ THIS!

Before loading software on your personal computer, please consider the security implications. I do not recommend running this software on a computer that stores your personal information. Additionally do not run this on your work computer without your employer’s written consent. The program is designed to consume nearly 100 percent of your available CPU cycles.

Thank you to all of the folks over at VMware that have made the deployment of the Appliance to easy. It was a great idea and even better execution!

Side note; In my homelab, I needed to have the vCenter running in order to deploy the appliance. Once it was deployed I powered the vCenter off to give the full CPU availability to the appliance (my environment is running on an Intel NUC).

Happy Folding!

vSphere 7 – vCenter Server Profiles Preview

As a decision-maker for several large projects, I constantly need to make difficult decisions regarding the purchase of software licensing. One of the things I look for is ‘what are those software vendors doing to reduce my operating costs’? Do they include tools to manage their products? Are they looking to their users to define their roadmap? VMware consistently delivers features and capabilities that make my life easier, Period.

Let me set the stage. For one of my primary projects, I support 60+ vCenter servers across multiple sites. To date, I have not found a single tool that can provide configuration and lifecycle management for our vCenter servers. To be perfectly honest the idea of backups and disaster recovery was really just an afterthought. In our shop, we found it just as easy to deploy a new vCenter than it was to fix an old or broken one.

I assume that while my environment might be on the extreme side of the envelope when it comes to the number of vCenters, the VMware community has desired a vCenter configuration management tool for some time.

Enter vSphere 7 and vCenter Server Profiles. Words cannot express my level of excitement for a vendor-supported solution! This new feature promises to deliver an interface that will allow vSphere administrators to easily and uniformly manage multiple vCenter servers.

vsp7_00

NOTE: THIS IS NOT HOST PROFILES!

Keep in mind that for the initial release there is no User Interface. All interaction is through REST APIs. Get out your console’s folks!

The API currently has four actions:

  • List – Provide a list of configurable items (by section)
  • Export – Exports the configuration profile via a JSON file.
  • Validate – Validates the configuration against a supplied JSON file.
  • Import – Imports a profile to vCenter Server via a JSON file.

The APIs will also be available in the API Explorer that is located in the Developer Center.

vsp7_02

The process seems pretty simple.

  1. Configure the ‘Gold’ or template vCenter
  2. Export the configuration
  3. Then Import the configuration to any vCenter that you want to be configured the same way!

vsp7_03

Configuration validation is one of the new features I look to take advantage of. I plan on writing a simple PowerShell process to run on a schedule that simply takes the exported ‘Gold’ copy of the configuration and validates it against all of my vCenters.

vsp7_01

I love this new addition to vSphere 7 and cannot wait to get my hands on it. Kudos to the VMware team for listening to its customers and community of users!

‘Open-ConsoleWindow -Count 3’ … It’s that easy

I’ve added a new function to the ‘jpsider’ module. I always find myself opening multiple console windows using the mouse. Yeah, I said it, I use the mouse! Well, it is too many clicks, so now I have a function that can open the new consoles for me! This will work for ‘PowerShell.exe’ and ‘Pwsh.exe’. I will need to do some testing on linux and Mac, as the current function will not work. If anyone has a desire for that please open an issue on GitHub for me.

Here is how you use it:

 
Install-Module -Name "jpsider" 
Open-ConsoleWindow -Count 3 -Executable "PowerShell.exe"

Or:

  
Open-ConsoleWindow -Count 3 -Executable "pwsh.exe"

Here is what it looks like – Notice I make use of the ‘Update-ConsoleTitle’ Function too!

NewConsole

#SayNoToMouse

Update-ConsoleTitle -Title “Why did I wait so long?”

Not sure about you, but I am constantly trying to keep track of multiple PowerShell console windows that I have open. I tend to try and update the title of the console by using the following line:

$Host.UI.RawUI.WindowTitle = "Some Fancy Title"

However, trying to remember that is a pain in the butt. So I have created a function and added it to a new Module on the PowerShell Gallery. Why did I wait so long to make a function for this?!?!


Install-Module -Name "jpsider"

Update-ConsoleTitle -Title "Some Fancy Title"

This function name is so much easier to remember. Hopefully, you will find it useful.

FancyTitle

I plan on adding more helpful functions to this module over time.

PowerShell Scaffolding – How I build modules.

Recently I’ve been getting quite a few inquiries about setting up modules for PowerShell. So, I’ve decided to write about it. Below you will read about how I go about creating a new PowerShell module.

Included in this Post:

  • Overview of Scaffolding
    • Plaster
  • My Module Template
    • Local testing files
  • AsBuiltReport
    • Run through an example

What is Scaffolding?

In it’s simplist form, its a common directory and file structure to help you build a PowerShell module. The directory structure helps separate build tools from the actual module/function files. There are two fairly popular scaffolding tools for PowerShell:

Plaster is the tool that I use to create new module scaffolding. I have found it easy to use and when I was first writing modules, there were quite a few blogs that did really well at helping me understand the process and tools. This was probably the most helpful link that I could find using Plaster. -> Kevin Marquette

My Module Template

Of course nothing in the PowerShell world is complete unless you have put your own twist or spin on it! Over time I have created my own Plaster template that I use to generate my own Modules. While the changes are small, it helps me rapidly generate all of the directories I desire to have in a module. My Module template can be found on GitHub.

My additions to the standard Plaster template are the following:

  • BuildSettings.ps1
    • Separate file to add any additional build settings. It keeps things clean IMO.
  • tests\RunPester.ps1
    • Allows developer to run Pester Tests on the full module on local box.
  • tests\RunPSScriptAnalyzer.ps1
  • tests\RunPSCodeHealth.ps1
    • Allows developer to run PSCodeHealth on the full module on local box.
  • Example Function and Unit test files
    • Disable-SSLValidation.ps1
      • Example Function (Located in Public and Private folders)
    • Disable-SSLValidation.Tests.ps1
      • Example Unit test file (Located in Public and Private folders)

AsBuiltReport

I’ve been talking with the guys who are working on the core functionality of the AsBuiltReport PowerShell Modules. They’ve asked me to scaffold out two of their repositories to help create an automated build pipeline for their modules. So lets walk through the process to show you how simple it can be.

  1. Install the Plaster Module
  2. Download my Plaster FullModule Template
  3. Run Plaster!

Step 1 – Is fairly easy, open a PowerShell console and run:


Install-Module Plaster<br data-mce-bogus="1">

 

 

Step 2 – Visit the link above and either Fork or clone the repository to your local machine.

Step 3 – Run Plaster, update the paths to match your local directories:


Invoke-Plaster -TemplatePath C:\OPEN_PROJECTS\Invoke-Automation\Powershell\Plaster\FullModuleTemplate\ -DestinationPath .\AsBuiltReport\

 

Then follow the prompts to create your new Module… It’s that simple!


==================================================
Name of your module (AsBuiltReport): AsBuiltReport.Cohesity.DataPlatform
Brief description on this module: AsBuiltReport.Cohesity.DataPlatform
Github repo name for this module (AsBuiltReport.Cohesity.DataPlatform):
GitHub username (AsBuiltReport):
Module author's' name (AsBuiltReport):
Initial module version (0.0.1):
Destination path: C:\temp\PLASTERSHIT\AsBuiltReport\
Creating folder structure
Create docs\images\
Create tests\
Create spec\
Create .vscode\
Create AsBuiltReport.Cohesity.DataPlatform\public\
Create AsBuiltReport.Cohesity.DataPlatform\private\
Create AsBuiltReport.Cohesity.DataPlatform\classes\
Create AsBuiltReport.Cohesity.DataPlatform\data\
Create tests\public\
Create tests\private\
Deploying files
Create appveyor.yml
Create build.ps1
Create BuildSettings.ps1
Create deploy.PSDeploy.ps1
Create .gitignore
Create .vscode\settings.json
Create spec\module.Steps.ps1
Create mkdocs.yml
Create PITCHME.md
Create readme.md
Create LICENSE
Create module.build.ps1
Create AsBuiltReport.Cohesity.DataPlatform\public\Disable-SSLValidation.ps1
Create AsBuiltReport.Cohesity.DataPlatform\private\Disable-SSLValidation.ps1
Create docs\about.md
Create docs\acknowledgements.md
Create docs\index.md
Create docs\Quick-Start-Installation-and-Example.md
Create tests\Project.Tests.ps1
Create tests\Help.Tests.ps1
Create tests\Feature.Tests.ps1
Create tests\Regression.Tests.ps1
Create tests\Unit.Tests.ps1
Create tests\RunPSCodeHealth.ps1
Create tests\RunPSScriptAnalyzer.ps1
Create tests\RunPester.ps1
Create tests\public\Disable-SSLValidation.Tests.ps1
Create tests\private\Disable-SSLValidation.Tests.ps1
Create spec\module.feature
Create AsBuiltReport.Cohesity.DataPlatform\AsBuiltReport.Cohesity.DataPlatform.psm1
Create AsBuiltReport.Cohesity.DataPlatform\AsBuiltReport.Cohesity.DataPlatform.psd1

This will create the entire directory structure as well as replace the new module name in all of the correct places withing each of the new/copied files. See the Repository used in this example on the AsBuiltReport GitHub.

Feel free to fork/update my Plaster template, I’m always interested to see what the community can come up with.

 

VMworld Hackathon 2019 – PowerCLI team

The annual VMworld Hackathon hosted by the VMwareCode team is one of my favorite events of the year. We get to hang out with community members, eat, drink and pound on keyboards in a competition where anything goes. I’ve participated in each of the last 4 events (US only), and for the first time I was on the winning team! Very exciting! Thank you to the VMwareCode team for continuing to support such a fun event for the community! It’s honestly less about competing and more about learning new things. One of the best parts is getting messages weeks later stating that I helped someone with some little keyboard trick.

hck

This year I put together a team and had a whole bunch of folks join to have some fun with the PowerCLI examples repository. The team was comprised of folks who had skills that ranged from novice to expert. Hopefully everyone learned a few things and could apply them to their normal jobs.

Huge thanks to all my team members. You guys were AWESOME & fun to work with!!

This Year’s Project:

The team would focus on creating an automated process around the PowerCLI Examples repository in GitHub. Some tasks would include:

  • Authoring a Build pipeline
  • Creating quality gates for deployment
  • Advanced Tasks
    • Resolve any current Lint Errors (There are Hundreds)
    • Implement auto-fix instructions during commits for common errors
    • Add Pester Tests for scripts

Why would this be a useful project?

The PowerCLI examples repository is simply a mess. A lot of folks have submitted useful scripts/examples/modules and other things to the repository but there is no consistency in the material. It’s unrealistic to think that one person or even a small group could provide the oversight needed on such a large repository to ensure that only quality/useful code was being published. Our Hackathon team focused on attempting to make this process a little more human friendly. Which would allow the repository owners to set up acceptance criteria and allow for the build process to determine if the code meets the requirements. Additionally it would be great for the consumer of the repository to have an easy method for downloading and using the PowerCLI examples.

What we decided on:

In talks with the team we adjusted the tasks for the night to focus on making the PowerCLI examples repository more user friendly from the Administrative and User side. This would include the following tasks for the night:

  • Create a new GitHub Repository to keep things clean
  • Only focus on the Scripts Directory
  • Convert all the Scripts to Functions
  • Package the Functions as a PowerShell Module
  • Scaffold a directory structure to support a PowerShell Module
  • Select a single Script, convert it to a function
    • Add Pester Tests for the Single script
  • Create CI/CD pipeline using AppVeyor
  • Publish new Module to the PowerShell Gallery
  • Review/Define quality gates
  • Run Linting tools against the newly created functions

What we accomplished:

The good news is that we were able to complete each of the tasks above, with only a few caveats.

  • All of the scripts were converted to functions and the Linting was run against them. However it would not make sense to blindly place all of these items in the Module.
    • The repository we worked from can be viewed on my GitHub page.
  • Only 1 function Get-MigrationsSet has unit tests, it would take some time to create the tests for all of the functions that were converted. See the first bullet.

How’s it work?

  1. The contributor 
    1. Forks the repository
    2. Creates a new Branch for their function
    3. Adds a Function file and appropriate test file
    4. Adds the appropriate Function and test code
      1. Can run tests locally 
    5. Commits code to their Branch and Fork
    6. Creates a Pull Request (PR) to the Master repository
  2. The Repository owner
    1. Reviews the Pull Request
      1. AppVeyor Results
      2. General code purpose
      3. Suggests any edits
    2. Approves or denies the PR
      1. If the PR is approved
        1. The Module is updated on the PowerShell Gallery
          1. Requires a string added to the Merge ‘!deploy’
  3. The Consumer
    1. Can Install the module from the PowerShell Gallery
      1. Install-Module PowerCLIExamples
    2. Can Update the module from the PowerShell Gallery
      1. Update-Module PowerCLIExamples

pipeline

What does the future hold?

Here are my suggestions for the ‘PowerCLI Examples Repository’ of the future….

  • Repository Ownership
    • It’s unclear the level of ownership that VMware should take for the repository and for the module(s). 
    • This comes down to legal responsibility and I cannot speak to what the outcome should or will be.
  • Modules
    • All of the current modules in the Module directory should be broken out into their own repositories. See first bullet.
    • All modules should still follow best practices outlined for the Module Quality gates that need to still be finalized
  • Scripts
    • All Scripts should be reviewed to determine if they are better suited as functions.
    • Scripts are okay, but are less user friendly as far as a Module goes.
    • Should still follow best practices outlined for the Module Quality gates that still need to be finalized
  • Functions
    • All functions should be reviewed to ensure they make sense. Are generally useful and not duplicated.
    • Should still follow best practices outlined for the Module Quality gates that still need to be finalized
  • Module Quality Gates
    • These need to be developed over time
      • Start small, Iterate often, Automate always
    • They will help every contributor write better code
    • Should not be overly complex for new contributors
      • Yes, there is still a learning curve