Manage Windows service using PowerShell

Windows service can be managed using few PowerShell cmdlets.

Udemy course: Migrate Windows service to Azure

Install Windows service into operating system:

New-Service -BinaryPathName .\PathTo\MyWinService.exe -Name MyWinService `
            -DisplayName "My Windows Service" -StartupType Automatic

List installed Windows services using wildcard:

Get-Service *my*

Get Windows service by name:

Get-Service MyWinService

Start Windows service:

Start-Service MyWinService


Get-Service MyWinService | Start-Service

Run Service Management Console to check in UI whether Windows service is installed and running:


Stop Windows service:

Stop-Service MyWinService


Get-Service MyWinService | Stop-Service

Uninstall Windows service from operating system in PowerShell 5.0 or previous:

(Get-WmiObject -Class Win32_Service -Filter "Name='MyWinService'").Delete()

Uninstall Windows service from operating system in PowerShell 6.0 or later:

Remove-Service MyWinService

If you are interested in Windows services and how to migrate them to Azure, take my Udemy course Migrate Windows service to Azure.

Deploy Azure WebJob using PowerShell

There are many posts on thema of Azure WebJob deployment using PowerShell. But I try to find the most simple solution possible and it is using the combination of PowerShell and Azure CLI.

Udemy course: Migrate Windows service to Azure

Following PowerShell script deploys Azure WebJob:

    [string] $buildOutput = $(throw "Directory with build output is required"),
    [string] $resourceGroupName = $(throw "Resource group name is required"),
    [string] $webAppName = $(throw "Web app name is required"),
    [string] $webJobName = $(throw "Web job name is required"),
    [string] $webJobType = "triggered"

$currentDir = (Get-Item .).FullName
$tempDir = "$currentDir\Temp"
$webJobDir = "$tempDir\App_Data\jobs\$webJobType\$webJobName"

New-Item $webJobDir -ItemType Directory
Copy-Item "$buildOutput\*" -Destination $webJobDir -Recurse
Compress-Archive -Path "$tempDir\*" -DestinationPath ".\$"
Remove-Item $tempDir -Recurse -Force

az webapp deployment source config-zip -g $resourceGroupName -n $webAppName --src "$"

PowerShell script has following parameters:

  • $buildOutput – Azure WebJob build output, in my case it is bin\Release\net472 folder
  • $resourceGroupName – Azure resource group name
  • $webAppName – Azure Web App name running on Azure App Service
  • $webJobName – Azure WebJob name
  • $webJobType – Azure WebJob type (triggered/continuous)

PowerShell creates temp directory and copy build output to the temp directory. The key part here is to use defined directory structure App_Data\jobs\$webJobType\$webJobName to deploy Azure WebJob to valid directory in Azure WebApp. Then create ZIP archive and remove temp directory. Then deploys Azure WebJob using Azure CLI command az webapp deployment to Azure.

If you are interested in Azure WebJobs and how to use them for Windows service migration to Azure, take my Udemy course Migrate Windows service to Azure where you learn more about Azure WebJob implementation, deployment, configuration and monitoring.

Migrate Windows service to Azure

My third Udemy course covers the thema of Windows service migration to Azure. Taking this course you learn:

  • Cloud service models
  • Benefits of migration to cloud
  • Alternatives for migration
  • Code changes
  • Preparing infrastructure (Azure Portal, Azure PowerShell, Azure CLI, ARM templates)
  • Deployment (Azure Portal, PowerShell)
  • Configuration (.config transformations, Azure Portal)
  • Logging and monitoring (Azure Application Insights)
  • Other options (Azure Functions, Azure Automation, Azure SQL Database Jobs, Hangfire)