How Do You Install Firefox on a Windows Server with PowerShell?

Problem scenario
You want to install Firefox on a Windows server without using the traditional GUI method. What should you do?

Solution
1. Open PowerShell ISE as Administrator (right click it, go to More -Run as Administrator).
2. Run this script (e.g., firefox.ps1):

# This script was mostly taken from https://forum.pulseway.com/topic/1940-install-firefox-with-powershell/

# www.continualintegration.com changed the version number of Firefox and added some comments
# Silent Install Firefox

# Download URL: https://www.mozilla.org/en-US/firefox/all/

# Path for the workdir
$workdir = “c:\installer\”

# Check if work directory exists if not create it

If (Test-Path -Path $workdir -PathType Container)
{ Write-Host “$workdir already exists” -ForegroundColor Red}
ELSE
{ New-Item -Path $workdir -ItemType directory }

# Download the installer

$source = “https://download.mozilla.org/?product=firefox-58.0.1-SSL&os=win64&lang=en-US”
$destination = “$workdir\firefox.exe”

# Check if Invoke-Webrequest exists otherwise execute WebClient

if (Get-Command ‘Invoke-Webrequest’)
{
Invoke-WebRequest $source -OutFile $destination
}
else
{
$WebClient = New-Object System.Net.WebClient
$webclient.DownloadFile($source,  » Read more..

How Do You Restart WMI Services with PowerShell?

Problem scenario
You want to restart Windows Management Instrumentation services using PowerShell. What command will cycle WMI in PowerShell?

Solution
Open PowerShell as an Administrator. Run this command: restart-service winmgmt

 » Read more..

How Do You Find the Version of Java that is Installed on Your Windows Server?

Problem scenario
You want determine what version of Java is installed (if any). What do you do?

Solution
Open PowerShell and run this command:
(Get-WmiObject Win32_Product | Where {$_.Name -match “Java”}).Version

Alternative way without PowerShell:
1. Go to Control Panel -Uninstall a Program
2. See if Java is installed

 » Read more..

How Do You Quickly Add a New Event to the Windows Logs Using PowerShell?

Problem scenario
You like adding logging messages manually in Linux/Unix. You do it from the command prompt with “# write a cool message here”. You review the messages with a “history” command. You also append messages to log files in /var/log/foorbar.d with ‘echo “note this” ‘. How do you introduce your own messages into Windows event log?

Solution
Run a command like this but change “Application” to “Security” or whichever log category you want:

Write-EventLog -LogName Application -EventId 3 -Message “Continual Integration helps!” -Source “Windows Error Reporting”

# Note that “Windows Error Reporting” is just one of several valid sources.  » Read more..

How Do You Get Azure PowerShell Commands Involving Storage to Work when They Are Returning an Error “not recognized”?

Problem scenario
Many Azure commands are failing. You installed the Azure module. But commands related to “Azure Storage” all return “not recognized as the name of a cmdlet, function, script file or operable program.”

You see messages like this:

New-AzureStorageAccount : A parameter cannot be found that matches parameter name ‘ResourceGroupName’.
At line:4 char:25
+ New-AzureStorageAccount -ResourceGroupName “contIntGroup” -AccountNam …
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-AzureStorageAccount],  » Read more..

How Do You Use a PowerShell Command to Stop an Azure VM?

Problem scenario
You have a server in Azure you want to turn off. What should you do to stop it?

Solution
Prerequisite
You need to know the server’s name and resource group. You can do this by finding the server in the Azure Portal.

Procedures
Run this command:

Stop-AzureRmVM -ResourceGroupName $nameOfResourceGroup -Name $nameOfVM

# Replace $nameOfResourceGroup with the name of the Resource Group.  » Read more..

How Do You Use a PowerShell Command to Destroy an Azure VM?

Problem scenario
You have a server in Azure you no longer need. You want to save money by deleting it. What should you do to eliminate it?

Solution
Prerequisite
You need to know the server’s name and resource group. You can do this by finding the server in the Azure Portal.

Procedures
Run this command:

Remove-AzureRmVM -ResourceGroupName $nameOfResourceGroup -Name $nameOfVM

# Replace $nameOfResourceGroup with the name of the Resource Group.  » Read more..

How Do You Use PowerShell to Find out if a Given Update Has Been Installed on Your Windows Workstation?

Problem scenario
You want to know if a particular KB was installed on your Windows machine. You know the KB number. How do you use PowerShell to find out if this update has been installed or not?

Solution
Run this: get-hotfix | sls “kb123456789” # Replace kb123456789 with the KB of your choice.

 » Read more..

How Do You Create the PowerShell Script, the Template.json and the Parameters.json Necessary to Utilize ARM?

Problem scenario
To use ARM templates you know know you should have three text files: 1) a PowerShell script 2) a template.json file and 3) a parameters.json file.

How do you create these for a given resource (e.g., a storage account, VM, or Function App)?

Solution
1.  In the Azure Portal web UI, start the process of creating a resource.  Right before you click “Create”,

 » Read more..

How Do You Use an ARM Template to Create an Azure Serverless Function App?

Problem scenario
As a proof-of-concept you want to use an ARM template to create an Azure Function that uses Azure storage.  You want the template to create the Azure storage account as it is a dependency of the Azure Serverless Function (also known as an App Service).  How do you do this?

Overview
This will create an Azure Function also known as an App Service.  The name of it will be entered interactively when the PowerShell script is run (when you are prompted for a “nameFromTemplate”).

 » Read more..