Windows service can be managed using few PowerShell cmdlets.
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 Windows service by name:
Start Windows service:
Get-Service MyWinService | Start-Service
Run Service Management Console to check in UI whether Windows service is installed and running:
Stop Windows service:
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:
If you are interested in Windows services and how to migrate them to Azure, take my Udemy course Migrate Windows service to Azure.
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.
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 ".\$webJobName.zip"
Remove-Item $tempDir -Recurse -Force
az webapp deployment source config-zip -g $resourceGroupName -n $webAppName --src "$webJobName.zip"
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.
My third Udemy course https://www.udemy.com/course/migrate-windows-service-to-azure 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)
I have 10+ years of experience with TFS and now I have an project which uses Git as source control system. I decided to wrote some notes which can help another experienced TFS users to start with Git. Key differences:
- Git is decentralized, while TFS has one central repository on TFS server. As for the Git there is one remote repository and then local repositories on developer machines. Due to this, the sync of commits between the repositories is needed.
- Git has commits, while in TFS we have changesets.
- Git branches are lightweight, while TFS branches allocates much more disk space.
- TFS get latest version = Git fetch + pull
- TFS check-in = Git commit + push
Next I will show some of the basic commands needed for the daily work. We start with cloning remote reposity using command:
git clone <repository_url>
Check the status and display current active branch:
Create new branch:
git checkout -b <branch_name>
Track new file:
git add <file_name>
Commit to local repository:
git commit -m "My commit message"
Push to remote repository:
Display list of last 5 commits:
git log -5
Display list of branches:
Merge from <other_brach> to current active branch:
git merge <other_branch>
Download commits from remote repository to local repository:
git fetch origin <branch_name>
Apply commits to local repository:
In this short post I used only command line commands, but this illustrates basic Git usage which can be also done with help of UI.
T-SQL query can be run parallel using combination of PowerShell Workflows and Invoke-Sqlcmd cmdlet as show in following code:
[string] $query = $(throw "Query is required"),
[string] $database = $(throw "Database name is required"),
[int] $parallelCount = 10
$numbers = [System.Linq.Enumerable]::Range(1, $parallelCount)
foreach -parallel ($number in $numbers)
Invoke-Sqlcmd -Database $database -Query $query
Invoke-SqlcmdParallel -query $query -parallelCount $parallelCount -database $database
Using this script you can easily simulate concurrency.
If you are interested in PowerShell automation, take my Udemy course Improve your productivity with PowerShell.