File System and Registry
Navigate drives, manage files and folders, and read/write the Windows Registry.
What You'll Learn
- PowerShell Provider drives (FileSystem, Registry, Env)
- Creating, copying, moving, and deleting files & folders
- Reading/writing the Windows Registry
- Managing environment variables
PowerShell Providers
PowerShell's Provider system is brilliant: it lets you navigate the file system, registry, environment variables, and certificates using the same commands โ Get-ChildItem, Set-Location, New-Item, etc.
๐ฏ Real-World Analogy: Imagine if you could browse the Windows Registry the same way you browse folders โ cd HKLM:\SOFTWARE then ls. That's exactly what Providers enable.
Get-PSDrive # List all available drives Get-PSProvider # List all providers cd HKCU:\Software # Navigate registry like folders! cd Env: # Browse environment variables cd Cert:\LocalMachine # Browse SSL certificates
File Operations
File management and reading/writing content.
// File System Operations โ simulated in JavaScript
console.log("=== PowerShell Provider Drives ===");
console.log();
console.log("PowerShell treats everything as a 'drive' via Providers:");
const drives = [
{ drive: "C:\\, D:\\", provider: "FileSystem", desc: "Files and folders" },
{ drive: "HKLM:\\, HKCU:\\", provider: "Registry", desc: "Windows Registry" },
{ drive: "Env:\\", provider: "Environment", desc: "Environment variables" },
{ drive: "Cert:\\", pr
...Registry & Environment Variables
The Windows Registry is a hierarchical database storing system and app configuration. PowerShell gives you full CRUD access using familiar Item cmdlets:
# Read a registry value $ver = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ProductName # Create a key for your app New-Item -Path "HKCU:\Software\MyApp" -Force # Set a value Set-ItemProperty "HKCU:\Software\MyApp" -Name "Theme" -Value "Dark"
โ ๏ธ Common Mistake
Editing HKLM:\ (Local Machine) requires Administrator privileges. Always run PowerShell as Admin when modifying machine-wide settings. HKCU:\ (Current User) doesn't need elevation.
Registry & Env Vars
Navigate the registry and manage environment variables.
// Windows Registry & Env Vars โ simulated in JavaScript
console.log("=== Windows Registry ===");
console.log();
console.log("PowerShell navigates the Registry like a file system:");
console.log();
console.log(" PS> Set-Location HKCU:\\Software");
console.log(" PS> Get-ChildItem # Browse registry keys");
console.log(" PS> Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion");
console.log();
console.log("=== Common Registry Tasks ===");
console.log(" # Read a value");
co
...๐ก Pro Tip
Use Get-Content -Wait to live-tail log files (like tail -f on Linux). Combine with Select-String for real-time filtering: Get-Content app.log -Wait | Select-String "ERROR".
๐ Quick Reference
| Cmdlet | Purpose |
|---|---|
| Get-ChildItem | List files / registry keys |
| Get-Content | Read file contents |
| Set-Content | Write to file (overwrite) |
| Test-Path | Check if path exists |
| Get-ItemProperty | Read registry values |
| $env:VARNAME | Access environment variable |
๐ Lesson Complete!
You can now manage files, registry keys, and environment variables like a pro. Next up: automating tasks and scheduling scripts.
Sign up for free to track which lessons you've completed and get learning reminders.