How to fix the error The term ‘Start-WebAppPool’ is not recognized as the name of a cmdlet

When you get the error: “The term ‘Start-WebAppPool’ is not recognized as the name of a cmdlet”

You will have to import the WebAdministration module

Like so:

Import-Module WebAdministration


But if you do this on a system that does NOT have PowerShell 5.1, you will have to install the Windows Management Framework 5.1


Else you will get the error:

Detected Windows PowerShell version 4.0. Windows PowerShell 5.1 is

required to load modules using Windows PowerShell compatibility feature.

Install Windows Management Framework (WMF) 5.1 from to enable this feature.

The error explains what to do, you should download the correct version of the WMF 5.1:


How to check version of PowerShell

> $PSversionTable


Side note

Restarting a Windows 2012 R2 server can take up to 10 minutes.


Notes on Module WebAdministration is loaded in Windows PowerShell using WinPSCompatSession remoting session

WARNING: Module WebAdministration is loaded in Windows PowerShell using WinPSCompatSession remoting session;

please note that all input and output of commands from this module will be deserialized objects.

If you want to load this module into PowerShell Core please use ‘Import-Module -SkipEditionCheck’ syntax.


But after unsing the parameter -SkipEditionCheck I got the error


Could not load type ‘System.Management.Automation.PSSnapIn’ from

assembly ‘System.Management.Automation, Version=,

Culture=neutral, PublicKeyToken=31bf3856ad364e35’.


So I did not used the -SkipEditionCheck, because the script was working correctly


Where to find info on the pwsh.exe


How to show all system paths on a new line with PowerShell

$env:path -split ‘;’


How to run a PowerShell 7 script on Windows 2012 R2 from the command line


You can use a shortcut or a small batch file.

I created a shortcut and used the following line as Target:

“C:\Program Files\PowerShell\7\pwsh.exe” -NoExit “deploy.ps1”

And used the folder containing the “deploy.ps1” as Start in location

NOTE: using the parameter -WorkingFolder did not work for me, so I used the “Start in” location


NOTE the file name must be the last parameter:

Default parameter if no parameters is present but any values is present in the command line. Runs the specified script in the local scope (“dot-sourced”), so that the functions and variables that the script creates are available in the current session. Enter the script file path and any parameters. File must be the last parameter in the command, because all characters typed after the File parameter name are interpreted as the script file path followed by the script parameters. Example: pwsh HelloWorld.ps1


Name parameters in C#, when calling a method

When you call a method in C# it is a good practice to name the parameters.
Certainly when dealing with Boolean values.

So instead of: contacts.Add(“My Name”, false);

Use: contacts.Add(“My Name”, shouldSaveToDb: false);

NOTE: If you name all parameters, the order does not matter.


Return custom error message instead of an exception from an ASP .NET Core controller

If you want an ASP .NET Core controller, to return an error message (not an exception), for example, when an parameter does not meet the requirements, then you can use the following code:

var response = new HttpResponseMessage


    Content = new StringContent(“Field ‘Birthdate’ should not be in the future.”),

    StatusCode = (HttpStatusCode.BadRequest)


return Task.FromResult(responseas IActionResult;



How to fix git push error

When you use an invalid branch name character, you will get the following error:

fatal: cannot lock ref ‘refs/heads/feature/Some_branchname_with_invalid_>_character’: Unable to create ‘…’: Invalid argument

error: src refspec feature/ Some_branchname_with_invalid_>_character does not match any

error: failed to push some refs to ‘ssh://git@…./…..git’

To fix this error remove all invalid branch name characters, in this case only the ‘>’ character.


How to insert lorem ipsem into a Microsoft Word document



















Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.