PowerShell for administrators
PowerShell is the modern shell for Windows Server. On a HolyCloud VPS, it lets you automate services, network, users, and updates without relying only on the GUI.
Prerequisites
- RDP or console session on the Windows VPS
- Account in the Administrators group
- Suitable execution policy (see below)
Run PowerShell as administrator
- Start menu → type PowerShell.
- Right-click → Run as administrator.
Check the version:
$PSVersionTable.PSVersion
Get-Host | Select-Object Version
PowerShell 5.1 is included by default; PowerShell 7 (pwsh) can be installed alongside for cross-platform scripts.
Script execution policy
Get-ExecutionPolicy -List
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
RemoteSigned: local scripts allowed; downloaded scripts must be signed.
Navigation and files
Get-Location
Set-Location C:\inetpub\wwwroot
Get-ChildItem -Force
New-Item -Path 'C:\Logs' -ItemType Directory
Copy-Item 'C:\source\app.config' -Destination 'C:\app\'
Remove-Item 'C:\Temp\old.log' -Force
System information
Get-ComputerInfo | Select-Object CsName, WindowsProductName, OsBuildNumber, OsLastBootUpTime
Get-CimInstance Win32_Processor | Select-Object Name, NumberOfLogicalProcessors
Get-CimInstance Win32_OperatingSystem | Select-Object TotalVisibleMemorySize, FreePhysicalMemory
Get-Volume
Windows services
Get-Service | Where-Object { $_.Status -eq 'Running' } | Sort-Object DisplayName
Get-Service W3SVC, TermService
Restart-Service W3SVC -Force
Stop-Service 'Spooler' -Force
Set-Service 'Spooler' -StartupType Disabled
Processes and performance
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10 Name, CPU, WS
Stop-Process -Name 'notepad' -Force -ErrorAction SilentlyContinue
Get-Counter '\Processor(_Total)\% Processor Time' -SampleInterval 2 -MaxSamples 5
Network
Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.IPAddress -notlike '127.*' }
Get-NetTCPConnection -State Listen | Select-Object LocalAddress, LocalPort, OwningProcess
Test-NetConnection -ComputerName 8.8.8.8 -Port 53
Resolve-DnsName www.holycloud.fr
Local users
Get-LocalUser
$Secure = Read-Host -AsSecureString 'Nouveau mot de passe'
New-LocalUser -Name 'deploy' -Password $Secure -Description 'Compte deploiement'
Add-LocalGroupMember -Group 'Administrators' -Member 'deploy'
Windows updates (overview)
Install-Module PSWindowsUpdate -Force -Scope AllUsers
Get-WindowsUpdate
Install-WindowsUpdate -AcceptAll -AutoReboot
Schedule reboots in a maintenance window.
Event log
Get-WinEvent -LogName System -MaxEvents 20 | Format-Table TimeCreated, Id, LevelDisplayName, Message -Wrap
Get-WinEvent -FilterHashtable @{LogName='Application'; Level=2; StartTime=(Get-Date).AddDays(-1)}
Level 2 = Error.
Pipeline and CSV export
Get-Service | Where-Object { $_.StartType -eq 'Automatic' } |
Select-Object Name, Status, DisplayName |
Export-Csv -Path 'C:\Reports\services-auto.csv' -NoTypeInformation -Encoding UTF8
Variables and simple scripts
File C:\Scripts\Disk-Alert.ps1:
param([int]$SeuilGo = 10)
$Disque = Get-PSDrive C
$LibreGo = [math]::Round($Disque.Free / 1GB, 2)
if ($LibreGo -lt $SeuilGo) {
Write-Warning "Espace disque C: faible ($LibreGo Go libres)"
}
Run:
& 'C:\Scripts\Disk-Alert.ps1' -SeuilGo 15
Built-in help
Get-Command *-NetFirewall*
Get-Help New-NetFirewallRule -Examples
Update-Help -Force -ErrorAction SilentlyContinue
Best practices
- Use
-WhatIfon destructive cmdlets when supported. - Log production scripts to
C:\Logs\. - Do not store passwords in plain text in scripts; prefer SecretManagement or interactive input.
- Test on a snapshot before large changes.
Troubleshooting
| ---------- | ---------- |
|---|---|
| « running scripts is disabled » | Set-ExecutionPolicy RemoteSigned |
| Access denied | Run PowerShell as administrator |
| Module not found | Install-Module / Import-Module |
| Broken UTF-8 characters | [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8 |
Need help?
For automation scripts related to HolyCloud infrastructure (API, snapshots), see VPS documentation or support with your specific use case.