Windows Server 2025 / PowerShell Basics: Objects, Pipelines, and Server Queries
PowerShell works with objects containing properties rather than only screen text. Combine query commands with Where-Object, Select-Object, and Sort-Object to inspect server information using explicit conditions.
Identify the shell and command help
These read-only examples target Windows PowerShell 5.1 on Windows Server 2025. A separately installed PowerShell 7 session can have different module compatibility. Restricted accounts may see less information even when a query does not normally require elevation.
$PSVersionTable Get-Command Get-Service Get-Help Get-Service -Examples
Get-Command checks availability; Get-Help explains usage and parameters. If local help is incomplete, check the official reference for the same version rather than executing a downloaded helper script. Verb-noun names also signal intent: Get and Set perform different kinds of work.
Inspect properties before processing output
A service object has a name, display name, status, and other properties. Work with those fields rather than cutting text according to displayed column positions. See PowerShell objects and their properties.
Get-Service | Select-Object -First 5 Get-Service | Get-Member Get-Service -Name WinRM | Select-Object Name,DisplayName,Status
Get-Member distinguishes properties from methods. Methods can perform actions, so do not invoke one merely because its name looks useful. This lesson queries and filters; it does not start or stop services.
Connect conditions with a pipeline
The vertical bar passes objects from one command to the next. This pipeline selects running services, sorts by name, and returns chosen columns. $_ denotes the current object:
Get-Service |
Where-Object { $_.Status -eq 'Running' } |
Sort-Object Name |
Select-Object Name,DisplayName,Status
For comparison, change only Running to Stopped, observe the different result set, then restore Running. The filter changes; actual services do not. -eq compares equality, -ne inequality, -gt greater-than, and -like patterns. Check data types when comparing numeric values rather than assuming displayed text behaves like numbers.
Use variables and explicit units
This query stores fixed-disk objects and calculates capacity and free space in gibibytes (GiB). PowerShell’s 1GB constant is 1,073,741,824 bytes; the column names show that binary unit.
$labDisks = Get-CimInstance Win32_LogicalDisk -Filter 'DriveType=3'
$labDisks | Select-Object DeviceID,
@{Name='SizeGiB';Expression={[math]::Round($_.Size / 1GB,1)}},
@{Name='FreeGiB';Expression={[math]::Round($_.FreeSpace / 1GB,1)}}
The variable contains disk objects, not a formatted table, and can be filtered again. Reserve Format-Table for the final human-readable display. Putting it before CSV export changes the objects into formatting data and loses the intended column structure. Values and row counts depend on the actual drives.
Keep queries and changes distinct
- Use Get-Command and help to identify the command and parameters.
- Record current values with query commands.
- For a change command supporting -WhatIf, inspect the proposed action.
- Assess operational effects and recovery separately from the preview.
- Keep a readable .ps1 file and record where it must run.
A missing command can mean a spelling error, absent module, or different shell version; it is not the same as access denied. Do not disable execution policy and security features together to make a script run. Follow the organization’s approved script and signing requirements.









