Appearance
Powershell Snippets
Search for a string in all files in the current directory and all subdirectories
powershell
Get-ChildItem -Path . -Recurse | Select-String -Pattern "string"
Replace a string in all files in the current directory and all subdirectories
powershell
$files = Get-ChildItem -Path . -Recurse
$files | ForEach-Object { (Get-Content $_.FullName) -replace "string", "replacement" } | Set-Content $_.FullName
Fetch a list of all installed programs
powershell
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | Select-Object DisplayName, DisplayVersion, Publisher | Sort-Object DisplayName
Fetch a list of all installed programs and save to a file
powershell
$date = Get-Date -Format "yyyy-MM-dd"
$file = "C:\Users\Public\Documents\InstalledPrograms_$date.txt"
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | Select-Object DisplayName, DisplayVersion, Publisher | Sort-Object DisplayName | Out-File -FilePath $file
Fetch all of user's environment variables
powershell
Get-Childitem -Path Env:* | Sort-Object Name