PowerShell Scripting for Windows VPS Administration: Automate Common Tasks

PowerShell is the backbone of Windows Server administration. For anyone managing a Windows VPS, mastering PowerShell means you can automate repetitive tasks, enforce configurations consistently, and respond to incidents faster than clicking through GUI dialogs. This guide covers practical PowerShell scripts for everyday Windows VPS administration: user management, IIS configuration, firewall rules, scheduled tasks, log rotation, disk monitoring, and automated reporting.

Running these scripts on a capable Windows VPS? Browse Windows VPS plans with Windows Server 2022 pre-installed and sufficient RAM for automation workloads.

Prerequisites

  • Windows Server 2019 or later (PowerShell 5.1+ included, PowerShell 7+ recommended)
  • Administrator privileges on the VPS
  • PowerShell execution policy set to allow scripts: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

1. User Management Automation

Create Multiple Local Users from a CSV

When onboarding a team, creating users one-by-one is tedious. Create a CSV file (users.csv) with columns Username,Password,FullName,Description then run:

Import-Csv "C:\Scripts\users.csv" | ForEach-Object {
     = ConvertTo-SecureString /home/ubuntu.Password -AsPlainText -Force
    New-LocalUser -Name /home/ubuntu.Username -Password  -FullName /home/ubuntu.FullName -Description /home/ubuntu.Description
    Add-LocalGroupMember -Group "Users" -Member /home/ubuntu.Username
}

Bulk Disable Inactive Users

Identify and disable users who have not logged in for 90 days:

 = (Get-Date).AddDays(-90)
Get-LocalUser | Where-Object { /home/ubuntu.LastLogon -lt  -and /home/ubuntu.Enabled -eq  } |
    ForEach-Object { Disable-LocalUser -Name /home/ubuntu.Name; Write-Host "Disabled: " }

2. IIS Management Scripting

Create an IIS Site with Application Pool

Import-Module WebAdministration
 = "MyNewSite"
 = "MyNewSiteAppPool"
 = "C:\inetpub\wwwroot\"
New-Item -Path  -ItemType Directory -Force
New-WebAppPool -Name  -Force
Set-ItemProperty "IIS:\AppPools\" managedRuntimeVersion ""
New-WebSite -Name  -Port 80 -HostHeader "www.mysite.com" -PhysicalPath  -ApplicationPool 
New-WebBinding -Name  -Protocol "https" -Port 443 -HostHeader "www.mysite.com"
Write-Host "Site created successfully."

3. Firewall Rule Management

 = @(80,443,21,3389)
foreach ( in ) {
     = "Allow Port "
    if (-not (Get-NetFirewallRule -DisplayName  -ErrorAction SilentlyContinue)) {
        New-NetFirewallRule -DisplayName  -Direction Inbound -Protocol TCP -LocalPort  -Action Allow
    }
}

4. Disk Space Monitoring

 = 10
Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" | ForEach-Object {
     = [math]::Round((/home/ubuntu.FreeSpace / /home/ubuntu.Size) * 100, 1)
    if ( -lt ) {
        Write-Host "WARNING: Drive  has only % free!" -ForegroundColor Red
    }
}

5. Scheduled Tasks via PowerShell

 = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\daily_maintenance.ps1"
 = New-ScheduledTaskTrigger -Daily -At 3am
 = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount
Register-ScheduledTask -TaskName "Daily VPS Maintenance" -Action  -Trigger  -Principal  -Force
Write-Host "Scheduled task created."

Conclusion

PowerShell transforms Windows VPS administration from manual, error-prone GUI work into repeatable, scriptable automation. The scripts in this guide cover the most common tasks: user management, IIS configuration, firewall rules, disk monitoring, log rotation, scheduled tasks, and health reporting. Start with one script, test it in your environment, and gradually build your automation library. For a reliable Windows VPS to run your automation on, compare Windows VPS hosting plans optimized for Windows Server workloads.

Leave a Comment