PowerShell Scripts for Windows Development
Explore a collection of practical PowerShell scripts designed to automate common tasks, manage Windows environments, and streamline your development workflow. These samples showcase the power and flexibility of PowerShell for system administration and developer productivity.
Get-SystemInfo.ps1
A comprehensive script to gather detailed system information, including hardware, OS version, network configuration, and running processes.
powershell -Command "& { Get-ComputerInfo | Select-Object CsName, OsName, OsVersion, OsManufacturer, OsBuildNumber, CsTotalPhysicalMemory, IpAddress -ExpandProperty IpAddress | Format-List }"
Manage-Services.ps1
Easily start, stop, restart, and query the status of Windows services. Useful for managing application dependencies or troubleshooting service issues.
powershell -Command "Get-Service -Name 'wuauserv' | Start-Service"
powershell -Command "Get-Service -Name 'Spooler' | Stop-Service"
Backup-UserProfiles.ps1
Automate the backup of user profiles to a specified network share or local directory, ensuring data safety.
# Example: Backup C:\Users\Public to \\Server\Backups\Public
robocopy "C:\Users\Public" "\\Server\Backups\Public" /MIR /Z /R:5 /W:5
Install-Application.ps1
A template script to silently install common applications using their MSI or EXE installers. Supports logging for troubleshooting.
$installerPath = "C:\Installers\MyApp.msi"
msiexec.exe /i $installerPath /qn /L*v "C:\Logs\MyApp_Install.log"
Monitor-DiskSpace.ps1
Checks disk space on specified drives and sends an alert if usage exceeds a defined threshold.
$threshold = 85 # Percentage
$drive = "C:\"
$freeSpace = (Get-PSDrive $drive).Free / 1GB
$totalSpace = (Get-PSDrive $drive).Used / 1GB + $freeSpace
$percentUsed = ($freeSpace / $totalSpace) * 100
if ($percentUsed -gt $threshold) {
Write-Host "ALERT: Disk space on $drive is at $percentUsed% usage."
# Add email or other notification logic here
}
Create-ScheduledTask.ps1
Utility to create and configure scheduled tasks for running scripts or programs at specific times or intervals.
New-ScheduledTask -TaskName "DailyReport" -Action (New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-File C:\Scripts\GenerateReport.ps1") -Trigger (New-ScheduledTaskTrigger -Daily -At "9:00 AM") -Description "Runs the daily report script"