logo
down
shadow

Powershell script to return search results from a list of keywords


Powershell script to return search results from a list of keywords

By : James Stone
Date : November 20 2020, 07:00 PM
this one helps. Your code works, the file is getting populated. However, what you have specified does not have the headers defined as in your screen shot. Also, what does that list.txt look like. My searchlist.txt is a single column file:
code :
Hello
client
$searchWords = gc 'D:\Scripts\searchlist.txt' 
$results = @()
Foreach ($sw in $searchWords)
{
    $files = gci -path d:\temp -filter "*$sw*" -recurse

    foreach ($file in $files)
    {
        $object = New-Object System.Object
        $object | Add-Member -Type NoteProperty –Name SearchWord –Value $sw
        $object | Add-Member -Type NoteProperty –Name FoundFile –Value $file.FullName
        $results += $object
    }

}

$results | Export-Csv d:\temp\searchresults.csv -NoTypeInformation


# Results
# psEdit -filenames 'd:\temp\searchresults.csv'

SearchWord FoundFile
---------- ---------
Hello      D:\temp\Duplicates\PowerShellOutput.txt
Hello      D:\temp\Duplicates\BeforeRename1\PowerShellOutput.txt
Hello      D:\temp\Duplicates\PoSH\PowerShellOutput.txt
Hello      D:\temp\Duplicates\Text\PowerShellOutput.txt
client     D:\temp\Client.txt
client     D:\temp\Duplicates\CertLabClients_v1.ps1
client     D:\temp\Duplicates\Check Logon Server for Client.ps1
client     D:\temp\Duplicates\Create Wireless Hosted Networks in Windows Clients.ps1
...
Hello,client
$searchWords = (gc 'D:\Scripts\searchlist.txt') -split ','
Foreach ($sw in $searchWords)
{
    Get-Childitem -Path "d:\temp" -Recurse -include "*.txt","*.csv" | 
    Select-String -Pattern "$sw" | 
    Select Path,LineNumber,@{n='SearchWord';e={$sw}}
}
# This is what my input looks like
Hello,client
595959, 464646 
LIC
$searchWords = ((gc 'D:\Scripts\searchlist.txt') -split ',').Trim()

Foreach ($sw in $searchWords)
{
    Get-Childitem -Path "d:\temp" -Recurse -include "*.txt","*.csv" | 
    Select-String -Pattern "$sw" | 
    Select Path,LineNumber,@{n='SearchWord';e={$sw}}
}

Path                                            LineNumber SearchWord
----                                            ---------- ----------
D:\temp\Duplicates\BeforeRename1\PsGet.txt             157 Hello     
...    
D:\temp\Duplicates\PoSH\PsGet.txt                      157 Hello     
...   
D:\temp\Duplicates\BeforeRename1\PoSH-Get-Mo...        108 client    
D:\temp\Duplicates\BeforeRename1\Powershell ...         12 client    
D:\temp\Duplicates\BeforeRename1\Powershell ...         15 client    
D:\temp\Duplicates\BeforeRename1\PsGet.txt             454 client    
...
D:\temp\newfile.txt                                      4 client    
D:\temp\MyFile.txt                                       5 595959    
D:\temp\ProcessNames.csv                                 4 595959    
D:\temp\Duplicates\Text\JSON-CSS.txt                    30 464646    
D:\temp\Duplicates\JSON-CSS.txt                         30 464646    
D:\temp\MyFile.txt                                       5 464646    
D:\temp\ProcessNames.csv                                 4 464646    
D:\temp\Duplicates\BeforeRename1\GetSetScree...          7 LIC 


Share : facebook icon twitter icon
jQueryUI Autocomplete - how to match search words with a list of keywords and show the matched results?

jQueryUI Autocomplete - how to match search words with a list of keywords and show the matched results?


By : ikadosh
Date : March 29 2020, 07:55 AM
will be helpful for those in need I don't the "search" event is the place to do what you're after. You should rather implement the source option as a callback:
code :
$("#searchTerms").autocomplete({
    ...
    source: function(request, response) {        
        var matched = [];
        // Search "request.term" through all links keywords
        for (var k = 0; k < links.length; k++) {
            if (checkSearchWordsMatchKeywords(request.term, links[k]['keywords'])) {
                matched.push(links[k]);
            }
        }
        // display the filtered results
        response(matched);
    }
});
Powershell script to search for file types from a list of machines, then copy results into directories named after the m

Powershell script to search for file types from a list of machines, then copy results into directories named after the m


By : namu
Date : March 29 2020, 07:55 AM
This might help you Move the Copy-Item inside the loop and add a statement to create the destination folder:
code :
$extensions = '*.xls*', '*.doc*', '*.txt', '*.pdf', '*.jpg', '*.pub'

Get-Content C:\computers.txt | % {
  $ComputerName = $_

  $dst = "\\destination\share\$ComputerName"
  $src = "\\$ComputerName\c$\Documents and Settings\**\desktop",
         "\\$ComputerName\c$\Documents and Settings\**\My Documents"

  New-Item -ItemType Directory $dst

  Get-Childitem $src -Include $extensions -Recurse -Force |
    Copy-Item -Destination $dst\
}
Search columns for keywords from a list and return any matches to a different column

Search columns for keywords from a list and return any matches to a different column


By : Iqbal Jeslee
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Hello and thanks in advance for any assistance. I have a work sheet with two tabs named DATA PULL and LIST. The LIST tab contains a list of keywords (250 words) in column A. I need to search for those key words in columns P and Q on the DATA PULL tab and return any matches to column I(the data is in a table). Columns P and Q contain multiple words or sentences. , Some tips for your code: Using a
code :
    On error Resume Next
    On Error goto 0
    If Sht.Cells(CommentLp, "P") Like "*" & Sht.Cells(wrdLp, "A") & "*" Then
        Sht.Cells(CommentLp, "I") = Sht.Cells(CommentLp, "I") & "; " & Sht.Cells(wrdLp, "A")
    End If
    Dim wrdLRow As Integer
    Dim wrdLp As Integer
    Dim CommentLrow As Integer
    Dim CommentLp As Integer
    Dim fndWord As Integer
    Dim DataSht As Worksheet
    Dim ListSht as Worksheet

    'Define the worksheets
    Set DataSht = Sheets("DATA PULL")
    Set ListSht = Sheets("LIST")


    'Get last row for words based on column A
    wrdLRow = ListSht.Cells(Rows.Count, "A").End(xlUp).Row

    'Get last row for comments based on column C
    CommentLrow = DataSht.Cells(Rows.Count, "P").End(xlUp).Row
    For CommentLp = 2 To CommentLrow
      For wrdLp = 2 To wrdLRow
        If LCASE(DataSht.Cells(CommentLp, "P")) Like "*" & LCASE(ListSht.Cells(wrdLp, "A")) & "*" Then
          If DataSht.Cells(CommentLp, "I") <> "" Then
            DataSht.Cells(CommentLp, "I") = DataSht.Cells(CommentLp, "I") & "; " & ListSht.Cells(wrdLp, "A")
          Else
            DataSht.Cells(CommentLp, "I") = ListSht.Cells(wrdLp, "A")
          End If
        ElseIf LCASE(Sht.Cells(CommentLp, "Q")) Like "*" & LCASE(Sht.Cells(wrdLp, "A")) & "*" Then
          If NewSht.Cells(writeRow, "A") <> "" Then
            NewSht.Cells(writeRow, "A") = NewSht.Cells(writeRow, "A") & "; " & Sht.Cells(wrdLp, "A")
          Else
            NewSht.Cells(writeRow, "A") = Sht.Cells(wrdLp, "A")
          End If
        End If
      Next wrdLp
    Next CommentLp
Python search column of text and return if there are any matching keywords from a list of words

Python search column of text and return if there are any matching keywords from a list of words


By : Prafulla Deshpande
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You can zip both columns for possible loop by tuples, loop by terms and test is membership in splitted values:
code :
terms = ['text', 'nothing']
a = [(x,i) for x, y in zip(df['message_id'],df['msg_lower']) for i in terms if i in y.split()]
print (a)
[(1116193453, 'text'), (9023746237, 'text'), (9023746237, 'nothing')]
terms = ['text', 'nothing', 'there meaning']

a = [(x, i) for x, y in zip(df['message_id'],df['msg_lower']) for i in terms if i in y]
print (a)
[(1116193453, 'text'), (9023746237, 'text'), 
 (9023746237, 'nothing'), (9023746237, 'there meaning')]
a = [(x, i) for x, y in zip(df['message_id'],df['msg_lower']) 
            for i in terms if re.findall(r"\b{}\b".format(i), y)]
Powershell search CSV file with no headers and non-standard delimeter; return only certain columns in results

Powershell search CSV file with no headers and non-standard delimeter; return only certain columns in results


By : yoga nanda
Date : September 11 2020, 02:00 AM
I hope this helps you . since i am too lazy to provide the data you didn't provide, i will skip reading the data in. you can use Get-Content for that. [grin]
what this does is ...
code :
$InStuff = 'empcode~1~0~TheFirstName~TheLastName~TheNickname~1~startdate~Supervisor~Location~TheDepartment~JobTitle~Extension'

$Header = @'
EmpCode
1stNumber
2ndNumber
FirstName
LastName
NickName
3rdNumber
StartDate
SupervisorName
Location
Department
JobTitle
Extension
'@ -split [System.Environment]::NewLine

$PropsToKeep = @(
    'FirstName'
    'LastName'
    'NickName'
    'Department'
    )

$OutStuff = $InStuff |
    ConvertFrom-Csv -Delimiter '~' -Header $Header |
    Select-Object -Property $PropsToKeep

$OutStuff
FirstName    LastName    NickName    Department   
---------    --------    --------    ----------   
TheFirstName TheLastName TheNickname TheDepartment
Related Posts Related Posts :
  • Powershell check if drive letter exists and if so remove
  • PowerShell copy fails without warning
  • Using powershell script with different parameters
  • Get Windows Last Reboot Timestamp?
  • In PowerShell how to capture error, warning, write-host output into a single file?
  • How to get the current script to read off computer names off a txt file located on c:\
  • Description property dont give back result
  • Not able to rename button base on value
  • EF6 Add-Migration in PowerShell, outside Visual Studio
  • How to uninstall dell support assist with powershell?
  • Get certificates information using powershell
  • My code will not write "No files to process"
  • PowerShell index value of PSObject
  • Powershell Foreach-Object behaves abnormaly on null values
  • How to list all installed, runnable cmdlets in powershell?
  • change powershell command color
  • How to install the WASP in powershell?
  • What would the opposite if this office 365 powershell command?
  • Start-Service cmdlet: get underlying error in case of failure
  • Import CSV File to a new Excel Worksheet within an existing Excel Workbook
  • Suppressing called function/cmdlet's WhatIf output, when that function has no WhatIf parameter
  • Deleting a specific tag in xml file
  • How to specify multiple files in $sourcePath
  • Function not working even though variable looks fine
  • I have a folder that contains multiple folders which contain images. I want to filter the images based on dimensions
  • Create multiple files with Powershell?
  • Get-WinEvent Select time and field within data item of 1
  • ConvertFrom-String returns symbol not text
  • How do I get the data results from Invoke-RestMethod into CSV file?
  • Set-ADUser does not handle empty or null variables
  • List Filename and current date of all files in a directory
  • PowerShell calling environment variable with another variable
  • Uninstall all software starting with a specific string
  • Removing spaces from a string using Powershell
  • Powershell environment variable
  • How to replace multiple characters (<3) of all the filenames in a folder (and subfolder) using PowerShell
  • Removing Parts of a File Name based on a Delimiter
  • How can we transform Date in CSV file using PowerShell scripts
  • new user powershell get-service
  • How to write a PowerShell script which auto increments a number by 1 every time it's run?
  • Replace the text for all files in a Directory
  • Copy files located in multiple subfolder, using a mildmatch search
  • How can I return multiple values from a powershell script to the batch file that is calling it?
  • Sensitive word search with powershell
  • How to use double if statement using powershell?
  • Command using either or both -Path parameter and $input?
  • My first parameter is not being passed to my function
  • How can I overwrite an existing zip file?
  • Creating Subdirectory With Date As Today(mm-dd-yyyy) in Network Drive
  • How do I remove IIS 'server' header from http response using Powershell?
  • New-Mailbox command does not accept the -Equipment argument
  • Adding Extra Headers in CSV
  • (Get-Date).ToUniversalTime() convert to string but not change format
  • Read CSV file then split the values and create a global variable
  • How to do looping to rename and read a file using PowerShell?
  • Is there a way in Powershell for a boolean parameter to automatically be true if not specified when the function is call
  • New-Partition -DriveLetter Option
  • How to add SAMAccountName to output?
  • compressed file syntax can be supported across all powershell version
  • How do I force a function to return a single element array instead of the contained object?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk