Skip to content

PowerShell Snippets

Will Wolff-Myren edited this page Aug 19, 2019 · 2 revisions

GetEnabledWindowsFeatures.ps1

# Get all enabled Windows Features, sorted by FeatureName
Get-WindowsOptionalFeature -Online | Where-Object State -eq "Enabled" | Sort-Object -Property "FeatureName" | Foreach { $_.FeatureName }

Find-TextInFiles.ps1

# https://win32.io/posts/How-To-Find-Text-PowerShell
Get-ChildItem "C:\path\to\folder"  -recurse | Where-Object { (Get-Content $_) -like '*TextToFind*' } | Select-Object { $_.FullName } 

# ...as a function:
function Find-TextInFiles($searchPath, $text) {
  Get-ChildItem $searchPath -recurse | Where-Object { (Get-Content $_) -like '*$text*' } | Select-Object { $_.FullName } 
}
Clone this wiki locally