How Do You Get PowerShell’s Invoke-Webrequest to Work Consistently (Instead of “command not found”)?

Problem scenario
You use invoke-webrequest and it works fine with some websites. But sometimes you find that PowerShell says “command not found.”  What is wrong?

Solution
invoke-webrequest will work to download html and htm files.  Depending on the source file on the web server, the command needs a flag to work properly.  For an image file with a .jpeg extension, the invoke-webrequest needs a flag “-ContentType ‘image/jpg'” or something similar to work. 

How Do You Install Java Version 8 on a Windows 64 Bit Server with PowerShell?

Problem scenario
You need to install Java version 8 on a Windows 64 bit server.  How do you do this with PowerShell?

Solution
1.  Open PowerShell ISE as Administrator.

2.  Run this script:

#  This is a modified version of PowerShell code taken from this site:
#  https://skarlso.github.io/2015/06/30/powershell-can-also-be-nice-or-installing-java-silently-and-waiting/

$JDK_VER=”1u151″
$JDK_FULL_VER=”8u151-b12″
$JDK_PATH=”1.8.0_151″
$source86 = “http://download.oracle.com/otn-pub/java/jdk/$JDK_FULL_VER/jdk-$JDK_VER-windows-i586.exe”
$source64 = “http://javadl.oracle.com/webapps/download/AutoDL?BundleId=230542_2f38c3b165be4555a1fa6e98c45e0808”
$destination86 = “C:\Program Files (x86)\$JDK_VER-x86.exe”
$destination64 = “C:\Program Files (x86)\$JDK_VER-x64.exe”
$client = new-object System.Net.WebClient
$cookie = “oraclelicense=accept-securebackup-cookie”
$client.Headers.Add([System.Net.HttpRequestHeader]::Cookie,

How Do You Create a Linux Server in Azure with PowerShell When You Keep Getting an Error “Status Code: 400…Bad Request”?

Problem scenario
You are trying to create a Linux server in Azure with the Azure Tools for PowerShell.  You receive this message:

“Destination path for SSH public keys is currently limited to its default value due to a known issue in Linux provisioning agent.”

You see  “StatusCode: 400 … ReasonPhrase: Bad Request.”

What do you do to create an Ubuntu 16.x server and not get this error?

How Do You Find What Resource Groups You Have with Azure PowerShell?

Problem scenario
You want to find the resource groups in your Azure account.  Either you have already installed Azure PowerShell on Windows 7 or on Windows 10 you have installed the Azure modules.  You have connected to an Azure account (e.g., with this command Login-AzureRMAccount). What is the PowerShell command to list the resource groups in the Azure account?

Solution
Run this command:
Find-AzureRmResourceGroup

# It will work with the Azure Cloud Shell too.

How Do You Use PowerShell on Your Desktop to Manage Azure?

Problem scenario
You want to use PowerShell on your local machine to create, delete, and restart servers in Azure.  You want to do other things with Azure using PowerShell on your workstation.  What do you do?

Solution
1.  To run Azure commands from your desktop, you need to connect your PowerShell ISE with your Azure instance.  If you are using Windows 10, see this posting and ignore this set of directions here entitled “How Do You Use PowerShell on Your Desktop to Manage Azure?” 

How Do You Create an Ubuntu Linux VM in Azure Using PowerShell Azure?

Updated 1/12/19

Problem scenario
You want to create an Ubuntu Linux server with one vCPU and one GB of RAM in Azure using PowerShell.  You want to use Azure Resource Manager (an ARM template).  You do not want to use the Azure Portal for 95% of the work involved.  What do you do to automate the process (including the deployment of a resource group, a network security group,

How Do You Generate a Load for Your Nginx or Apache Web Server?

Problem scenario
You set up a load balancing mechanism for your Nginx or Apache web server.  You want to test it and set up an artificial load of traffic.  You want to generate a significant amount of traffic to test the HTTP load balancing mechanism.  How do you do this?

Solution
Here are three scripts that can, by themselves, download a web page 100 times when they execute. 

How Do You Detect the Hard Drive Letter That Your PowerShell Script (.ps1 File) Is Saved On?

Problem scenario
You have a PowerShell script that you want to be able to detect the hard drive letter it resides on.  How can PowerShell detect the hard drive letter that the .ps1 file itself is stored on?

Solution
Use this command: (get-location).drive.name

To get the drive letter to be in a variable named $dl, use this:
$dl = (get-location).drive.name

Now you can use $dl as the drive letter in the PowerShell script.  

How Do You Use JEA (Just Enough Administration) to Give Users the Rights to Perform Select PowerShell Tasks?

Problem scenario
You want to empower non-administrator users to perform a subset of Windows administrator-level functions.  Specifically you want to give a user with limited privileges the ability to check the local software firewall rules.  This user needs to validate if they are configured appropriately.  This user account will otherwise have limited privileges.  You want to adhere to the recommended practice of least privileges.  You want to use JEA (Just Enough Administration) to enhance the user’s privileges. 

How Do You Find Files That Were Modified Recently and Have a Specific String in Their Name?

Problem scenario
On a Windows computer you want to find .txt files that were modified within the past four days. Using PowerShell you want to find files in a directory and its subdirectories that were modified within a certain time (within the past four days) and have a pattern in the name of “.txt”. How do you search every folder on the computer (or server) to filter files with