Windows Scripting Samples
Explore a comprehensive collection of code samples to help you automate tasks, manage systems, and develop powerful applications using Windows scripting technologies.
Featured Scripting Languages
-
Introduction to PowerShellPowerShell
Learn the basics of Windows PowerShell, the task-based command-line shell and scripting language.
-
Visual Basic Scripting Edition (VBScript) EssentialsVBScript
Discover fundamental VBScript concepts for automating Windows operations.
-
Command Prompt (CMD) ScriptingCMD
Effective use of batch files and command-line commands for system administration.
Common Scripting Scenarios
-
Active Directory ManagementPowerShell
Scripts for user, group, and organizational unit management.
-
File System AutomationVBScript/PowerShell
Examples for file manipulation, copying, moving, and deleting.
-
Windows Service ManagementPowerShell
Scripts to start, stop, restart, and query Windows services.
-
Network ConfigurationPowerShell
Automate IP address configuration, DNS settings, and network adapter management.
A Quick PowerShell Example: Get System Information
Here's a simple PowerShell script to retrieve basic system information:
# Get the operating system name and version
$os = Get-CimInstance -ClassName Win32_OperatingSystem
Write-Host "Operating System: $($os.Caption)"
Write-Host "Version: $($os.Version)"
# Get the computer name and domain
$computerInfo = Get-CimInstance -ClassName Win32_ComputerSystem
Write-Host "Computer Name: $($computerInfo.Name)"
Write-Host "Domain: $($computerInfo.Domain)"
# Get processor information
$processor = Get-CimInstance -ClassName Win32_Processor
Write-Host "Processor: $($processor.Name)"
Write-Host "Number of Cores: $($processor.NumberOfCores)"
# Get total physical memory
$memory = Get-CimInstance -ClassName Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum
$totalMemoryGB = [math]::Round($memory.Sum / 1GB, 2)
Write-Host "Total Physical Memory: $($totalMemoryGB) GB"
To run this, save it as a .ps1
file and execute it from a PowerShell prompt.