PowerShell scripts for system administrators

Top 10 PowerShell Scripts Every System Administrator

PowerShell is a powerful automation tool for Windows administrators. It allows you to manage servers, perform automated tasks, and solve common problems without using complex graphical interfaces. In this article, we will look at the top 10 PowerShell scripts that will make your work much easier and improve your efficiency.

1. Getting a list of all installed programs

With PowerShell, you can quickly get a list of all installed programs on the system.

Get-WmiObject -Class Win32_Product | Select-Object Name, Version

This script displays a list of programs with their names and versions, which is useful for inventory and updates.

2. Checking the service status

To check the service status, you can use the following script:

Get-Service -Name “wuauserv” | Select-Object Status, Name

Replacing “wuauserv” with the name of any service will give you its status (running or stopped).

3. Getting disk information

3. Getting disk information To quickly get information about hard drives, you can use this script:

Get-PhysicalDisk | Select-Object DeviceID, FriendlyName, OperationalStatus, Size

This script displays details about each physical disk, including status and size.

4. Monitoring CPU Usage

To find out the current CPU load on the system, use:

Get-WmiObject -Class Win32_Processor | Select-Object LoadPercentage

This is useful for monitoring and diagnosing performance issues.

5. Search for unused files

This script allows you to search for files that have not been used in the last 30 days:

Replace “C:\path\to\directory” with the path to the desired folder. This will help clean up your drives from unnecessary data.

6. Getting a list of users in a domain

To get a list of users from Active Directory:

Get-ADUser -Filter * | Select-Object Name, SamAccountName

This script is useful for administering Active Directory.

7. Cleaning up temporary files

To clean up temporary files and free up disk space:

Remove-Item -Path “C:\Windows\Temp\*” -Recurse -Force

This will help clean up temporary folders that often accumulate unnecessary files.

8. Sending email notifications

With PowerShell, you can send email notifications about task statuses:

Send-MailMessage -From “[email protected]” -To “[email protected]” -Subject “PowerShell Notification” -Body “This is a test email.” -SmtpServer “smtp.domain.com”

This is useful for notifications about task completion or errors.

9. Checking the availability of remote servers

To check the availability of servers on the network, you can use the command:

Test-Connection -ComputerName “server.domain.com” -Count 4

This is useful for diagnosing network problems and monitoring the status of servers.

10. Backing up files

To create a backup copy of an important folder, use the following script:

Copy-Item “C:\path\to\important\folder” -Destination “D:\backup\folder” -Recurse

This allows you to create copies of data to protect against loss.

PowerShell is an indispensable tool for system administrators. With these top 10 scripts, you can automate many routine tasks and increase your work efficiency. Every administrator should master at least a few of them to improve their daily work.


Leave a Reply

Your email address will not be published. Required fields are marked *

About Us

We are a team of IT enthusiasts, publishing practical articles for system administrators: automation, security, infrastructure and the best tools for daily work.

treefancy.com
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.