Easy PowerShell Scripts for Windows Server 2025 Management

As Windows Server 2025 continues to evolve, system administrators are faced with increasingly complex environments. Fortunately, PowerShell provides an efficient way to automate repetitive tasks, streamline management, and reduce human error. Whether you’re managing Active Directory, monitoring server health, or handling patch management, PowerShell scripts can significantly reduce your workload.

In this blog post, I’ll walk you through some of the most powerful and useful PowerShell scripts that can help automate various aspects of Windows Server 2025 management. These scripts are designed to save time and improve the overall efficiency of your server administration.


1. Listing All Domain Controllers in Your Environment with Powershell Scripts

When managing multiple domain controllers (DCs), it’s important to have a clear overview of your Active Directory infrastructure. This script allows you to list all domain controllers in your environment and export their details to a CSV file for easy documentation.

Get-ADDomainController -Filter * | Select-Object Name, Site, IPAddress, OperatingSystem | Export-Csv -Path "C:\DCList.csv" -NoTypeInformation

Breakdown:

  • Get-ADDomainController: Retrieves information about all domain controllers.
  • Select-Object: Filters out only the relevant properties (Name, Site, IP Address, Operating System).
  • Export-Csv: Exports the results into a CSV file for further analysis or reporting.

This script is particularly useful when performing audits or preparing for migrations and upgrades.

More details on Microsoft Learn – Get-ADDomainController any my Blog Powershell – List all domain controllers and more for the new Windows Server 2025


2. Automating Group Policy Object (GPO) Reports

Group Policy Objects (GPOs) are essential for managing security settings across your domain. However, manually auditing GPOs can be time-consuming. This script generates a comprehensive report of all GPOs in your environment and exports it as an HTML file.

Get-GPOReport -All -ReportType HTML -Path "C:\Reports\GPOReport.html"

Breakdown:

  • Get-GPOReport: Retrieves detailed reports on all GPOs.
  • -ReportType HTML: Specifies the format of the report (HTML in this case).
  • -Path: Defines where the report will be saved.

This report can be opened in any web browser and provides a full overview of all GPOs, including their settings and status. It’s an excellent tool for auditing and troubleshooting Group Policy issues.

More details on Microsoft Learn – Get-GPOReport and my Blog Active Directory – Group Policy Report


3. Monitoring Event Logs for Critical Errors with Powershell Scripts

Event logs provide valuable insights into what’s happening on your servers. However, manually checking logs every day is inefficient. This PowerShell script automates the process by filtering out critical errors from the System event log and exporting them to a CSV file.

$ErrorEvents = Get-WinEvent -LogName System | Where-Object {$_.LevelDisplayName -eq "Error"}
$ErrorEvents | Export-Csv -Path "C:\Logs\SystemErrorLogs.csv" -NoTypeInformation

Breakdown:

  • Get-WinEvent: Retrieves events from specified logs (in this case, the System log).
  • Where-Object: Filters out only events marked as “Error”.
  • Export-Csv: Exports the filtered events to a CSV file for further analysis.

This script is ideal for proactive monitoring and helps you identify potential issues before they escalate into critical problems.

More details on Microsoft Learn – Get-WinEvent and my Blog Tail for Logfiles


4. Automating Disk Space Monitoring with Powershell Scripts

Low disk space can cause major disruptions on a server. Instead of manually checking available space on each drive, use this PowerShell script to monitor disk space across all drives and receive alerts when space is running low.

$drives = Get-WmiObject Win32_LogicalDisk -Filter "DriveType=3"
foreach ($drive in $drives) {
    if ($drive.FreeSpace / $drive.Size -lt 0.1) {
        Write-Host "Warning: Low disk space on drive $($drive.DeviceID)"
    }
}

Breakdown:

  • Get-WmiObject Win32_LogicalDisk: Retrieves information about all logical disks.
  • DriveType=3: Filters the results to include only local hard drives.
  • The script then checks if free space is less than 10% (FreeSpace / Size < 0.1) and outputs a warning if true.

This with Powershell Scripts can be easily extended to send email alerts or log warnings into a file for later review.


5. Automating Windows Updates Installation

Keeping servers up-to-date with patches is crucial for security and stability. This script automates the process of checking for updates, downloading them, and installing them silently without requiring user interaction.

Install-WindowsUpdate -AcceptAll -AutoReboot

Breakdown:

  • Install-WindowsUpdate: A command from the PSWindowsUpdate module that checks for available updates.
  • -AcceptAll: Automatically accepts all updates without user intervention.
  • -AutoReboot: Automatically reboots the server if required after updates are installed.

Before using this script, ensure that you have installed the PSWindowsUpdate module by running:

Install-Module PSWindowsUpdate

This script is perfect for automating patch management across multiple servers without manual intervention.


6. Creating Scheduled Tasks via with Powershell Scripts

Scheduled tasks are an essential part of server administration for automating recurring tasks such as backups or maintenance scripts. This PowerShell script creates a new scheduled task that runs a backup script every day at midnight.

$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\BackupScript.ps1"
$trigger = New-ScheduledTaskTrigger -Daily -At 12:00AM
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "DailyBackup" -Description "Runs daily backup at midnight"

Breakdown:

  • New-ScheduledTaskAction: Defines what action should be taken (in this case, running a PowerShell script).
  • New-ScheduledTaskTrigger: Sets up when the task should run (daily at midnight).
  • Register-ScheduledTask: Registers the task with Task Scheduler using the specified action and trigger.

This is an excellent way to automate routine maintenance tasks without having to log in manually each time they need to be performed.


7. Managing Services Across Multiple Servers

Managing services across multiple servers can be tedious if done manually. This PowerShell script allows you to start or stop services on multiple servers simultaneously by specifying their names in an array.

$servers = @("Server01", "Server02", "Server03")
foreach ($server in $servers) {
    Invoke-Command -ComputerName $server -ScriptBlock {
        Start-Service -Name 'Spooler'
        Write-Host "Started Spooler service on $($env:COMPUTERNAME)"
    }
}

Breakdown:

  • Invoke-Command: Executes commands remotely on specified servers.
  • The script starts the ‘Spooler’ service on each server listed in $servers.

This approach saves significant time when managing services across multiple machines in large environments.


8. Automating Application Updates

Keeping servers up-to-date with applications is crucial for security and stability. With Windows Server 2025 and WinGet you can finally automate installing and updating Windows App Store and Windows 3rd Party Apps using many repositories. The below example does upgrade all applications. If you are interested check my blog “Easily manage Applications with WinGet v1.x” covering this in more details.

winget upgrade --all

Breakdown:

  • Winget: A standard command from Windows 10, Windows 11 and Windows Server 2025 to update and install software
  • Upgrade: Upgrade the detected and installed software
  • –all: Automatically do this for any detected software package

Conclusion

PowerShell is an incredibly powerful tool that can simplify many aspects of Windows Server 2025 management. By automating routine tasks like monitoring event logs, managing disk space, installing updates, and handling services across multiple servers, administrators can focus on more strategic initiatives rather than repetitive tasks.

The scripts provided here are just scratching the surface of what’s possible with PowerShell automation. As your environment grows more complex, consider building custom scripts tailored to your specific needs or integrating these scripts into larger automation workflows using tools like System Center or Azure Automation.

If you want a more personal experience with Powershell I do recommend to customize it. Take a look at how my Terminal looks like and learn how to customize it.

Terminal - Fully customized for more fun with PowerShell Scripts
Terminal – Fully customized for more fun with PowerShell Scripts

Spread the knowledge
Avatar for Andreas Hartig
Andreas Hartig - MVP - Cloud and Datacenter Management, Microsoft Azure

Related Posts

A dragon IT architect from the shadowrun world sitting on an egg protecting Active Directory

Windows Server 2025 – Part 7 (Active Directory Hardening)

In today’s world, cybersecurity is not just a necessity; it’s a foundation for your business’s integrity and trustworthiness. One of the key components of this foundation is Active Directory hardening….

Spread the knowledge
Read more
A dragon IT Architect in the shadowrun world looking very intensively and focussed into Microsoft Windows Server Event Viewer Logfiles

Windows EventLog for Windows LAPS Events

To monitor Windows LAPS (Local Administrator Password Solution) activities in the Windows Event Log, you can track specific Event IDs.  Key Windows LAPS Events IDs The following events provide critical…

Spread the knowledge
Read more
A dragon IT Architect in the shadowrun world, sitting in a datacenter and having a trust relationship issue

Repairing the Domain Trust Relationship – No Reboot

When managing an Active Directory environment, one of the common issues you might encounter is a broken Domain Trust between a workstation, server and the domain. This can be frustrating,…

Spread the knowledge
Read more
A dragon who is an IT Architect in the shadowrun world currently creating the Active Directory OU structure on Windows Server 2025

Windows Server 2025 – Part 6 (Active Directory Design)

When creating an Active Directory structure it is good to develop the Active Directory design with a focus for efficient management, delegation of administrative tasks, and application of Group Policies…

Spread the knowledge
Read more
Windows Server 2025 Part 1

Windows Server 2025 – Part 1 (Preparation)

Microsoft released the Windows Server 2025 and made it officially available on the 1st of November 2025. With the latest changes in the server and datacenter Virtualization market, i wanted…

Spread the knowledge
Read more
Windows Server 2025 - Install Active Directory

Windows Server 2025 – Part 5 (Active Directory)

How to set up Active Directory on Windows Server 2025? Despite servers being enabled for Entra ID, formerly known as Azure Active Directory, almost all buisness Windows Server installations will…

Spread the knowledge
Read more