Posted On March 7, 2022

PowerShell: Search File Contents Matching a Phrase or String

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Search File Contents Matching a Phrase or String
$searchDirectories='C:\users\Public\.jenkins\jobs'
$searchDepth=1
$fileNameScope='*.xml'
$searchString='kimconnect'

# Select the files and perform the search in each file
$files=Get-ChildItem -Path $searchDirectories -Depth $searchDepth -Filter $fileNameScope
$files|%{
    $x=Select-String -Path $_ -Pattern $searchString;
    if($x){
        write-host "File $_ contains $searchString`r`n$x`r`n"
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Kubernetes: Cert-Manager x509 ECDSA verification failure

Symptoms Error from server (InternalError): error when creating "kimconnect-cert.yaml": Internal error occurred: failed calling webhook…

PowerShell: Trigger Azure AD Sync on Remote Server as a Domain Admin

# Trigger-AD-Sync.ps1# Requirements: https://blog.kimconnect.com/powershell-install-rsat/## This script does these things:# a. Obtain Domain Admin credential# b.…

PowerShell: Use Selenium Drivers to Automate Logins

Set Variables: $username='testrobot' $password='password' $url='https://blog.kimconnect.com' # Version 0.0.2 - return true or false, while keeping…