How Do You Create a PowerShell Script to Create a Storage Account in Azure?

Problem scenario
You want to use an ARM template via a PowerShell script to create a storage account in Azure.  How do you do this?

Solution
Prerequisites

1.  If you are using Windows 7, you have installed Azure PowerShell; if you need assistance with this, see this posting.  If you are using Windows 10, you have installed the modules for Azure and the storage resource;

 » Read more..

How Do You Install Azure PowerShell on Windows 10?

Problem scenario
You want to run ARM templates to declaratively create resources such as servers, databases, and subnets in Azure.  You need the PowerShell module for Azure to be installed for certain “reserved” words to work.  How do you install the Azure PowerShell?

Solution
1.  Open PowerShell as administrator.  (PowerShellGet is built into Windows 10 by default.  It may appear uninstalled, but it is natively part of the OS.)
2. 

 » Read more..

How Do You Find the Subscription ID for an Azure Account?

Problem scenario
You want to find the subscription ID for your Azure account.  What do you do?

Possible Solution #1
Log into the Azure Portal.  In the upper right click on your account and then click on “My permissions.”  You should see an alphanumeric string near your subscription.

Possible Solution #2
Prerequisite

If you have Windows 7 you need to install Azure PowerShell;

 » Read more..

How Do You Troubleshoot the PowerShell Error “Cannot connect to CIM Server: Access is denied”?

Problem scenario
You run a PowerShell command with a user who is not a local administrator on the server.  You get the error “Cannot connect to CIM server: Access is denied”.  How do you circumvent this error?

Possible solution #1
Make the user a local administrator.  Then try again.

Possible solution #2
Use JEA to allow the user to run the command. 

 » Read more..

How Do You Troubleshoot the Powershell Error “Cannot find Get-Command”?

Problem scenario
You run a PowerShell command.  You get “Cannot find Get-Command” even though the command you entered was not Get-Command.  How do you solve this error?

Possible Solution #1
As an Admininstrator of the server, go to Server Manager -Tools -Computer Management.  In this Window (or MMC) go to System Tools -Local Users and Groups -Users.  Double click on the User that received the error.  

 » Read more..

How Do You SSH to a Windows Server or How Do You Install Cygwin on a Windows 2016 Server?

Problem scenario
You want to install Cygwin to allow for SSH connections (from Linux servers) to your Windows server.  How do you do this?

Solution
1.  If the server is new, skip step #1.

  a)  Log in and go to Control Panel -> System and Security -> System.  Click on “Advanced system settings” on the left.

  b)  Go to the Advanced tab and click on “Environment Variables…”

 

 » Read more..

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. 

 » Read more..

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,

 » Read more..

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?

 » Read more..

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.

 » Read more..