#Windows Server for DevOps

While Linux dominates DevOps, Windows Server is essential for .NET applications and hybrid environments.

#📋 Table of Contents


#Windows Server Editions

EditionUse Case
Windows Server 2022Latest, recommended
Server CoreMinimal install, recommended for DevOps
Nano ServerContainer-optimized

#PowerShell Basics

PowerShell is the command-line interface for Windows automation.

#Essential Commands

powershell
1# Get help
2Get-Help Get-Process
3Get-Command *service*
4
5# List processes
6Get-Process
7Get-Process -Name nginx
8
9# Stop process
10Stop-Process -Name notepad
11Stop-Process -Id 1234
12
13# Services
14Get-Service
15Get-Service -Name W3SVC
16Start-Service -Name W3SVC
17Stop-Service -Name W3SVC
18Restart-Service -Name W3SVC
19
20# File operations
21Get-ChildItem              # ls equivalent
22Copy-Item source dest      # cp equivalent
23Move-Item source dest      # mv equivalent
24Remove-Item file           # rm equivalent
25
26# Network
27Test-NetConnection google.com -Port 443
28Get-NetIPAddress
29Get-NetTCPConnection

#Scripting Example

powershell
1# health-check.ps1
2$servers = @("server1", "server2", "server3")
3
4foreach ($server in $servers) {
5    $result = Test-NetConnection -ComputerName $server -Port 80
6    if ($result.TcpTestSucceeded) {
7        Write-Host "✓ $server is healthy" -ForegroundColor Green
8    } else {
9        Write-Host "✗ $server is unhealthy" -ForegroundColor Red
10    }
11}

#Windows Services

powershell
1# Create a new service
2New-Service -Name "MyApp" `
3    -BinaryPathName "C:\Apps\myapp.exe" `
4    -DisplayName "My Application" `
5    -StartupType Automatic
6
7# Configure service recovery
8sc.exe failure MyApp reset= 86400 actions= restart/60000/restart/60000/restart/60000
9
10# Remove service
11Remove-Service -Name "MyApp"

#IIS Web Server

powershell
1# Install IIS
2Install-WindowsFeature -Name Web-Server -IncludeManagementTools
3
4# Create website
5New-Website -Name "MyApp" `
6    -PhysicalPath "C:\inetpub\myapp" `
7    -Port 80
8
9# Start/Stop website
10Start-Website -Name "MyApp"
11Stop-Website -Name "MyApp"
12
13# Application pool
14New-WebAppPool -Name "MyAppPool"
15Set-ItemProperty "IIS:\AppPools\MyAppPool" -Name "managedRuntimeVersion" -Value "v4.0"

#Windows Containers

powershell
1# Install Docker on Windows Server
2Install-WindowsFeature -Name Containers
3Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
4Install-Package -Name Docker -ProviderName DockerMsftProvider
5
6# Start Docker
7Start-Service Docker
8
9# Run Windows container
10docker run -d -p 80:80 mcr.microsoft.com/windows/servercore/iis
11
12# Build Windows container image
13docker build -t myapp:latest .

#Dockerfile for .NET App

dockerfile
1FROM mcr.microsoft.com/dotnet/aspnet:6.0-windowsservercore-ltsc2022
2WORKDIR /app
3COPY ./publish .
4ENTRYPOINT ["dotnet", "MyApp.dll"]

#Summary

TaskCommand
List servicesGet-Service
Start serviceStart-Service -Name name
Test portTest-NetConnection host -Port 80
Install featureInstall-WindowsFeature -Name feature
Run containerdocker run image

[!TIP] Pro Tip: Use Windows Server Core for DevOps - it's smaller, more secure, and easier to automate than the GUI version!