$webClient = new-object System.Net.WebClient
$webClient.Headers.Add("user-agent", "PowerShell Script")
$keyword = read-host "Keyword:"
$info = get-content c:\users\dell\desktop\urls.txt

foreach ($i in $info) {
    $output = ""
    $output = $webClient.DownloadString($i)

    if ($output -like "*$keyword*") {
        $b = Get-Date
        $ButtonType = [System.Windows.MessageBoxButton]::Ok
        $MessageboxTitle = “Open Source Information Collection”
        $Messageboxbody = "Detected the keyword $keyword at $b"
        $MessageIcon = [System.Windows.MessageBoxImage]::Asterisk


The code does gets the content from various websites listed in the urls.txt file, and searches for a specific keyword.

If the keyword is found, the user is notified.

However, what I am missing, is for the program to not only notify the user that a keyword was found to match the content, but also to say which website the content that matches with the keyword has originated from.



I think the URL you are looking for is located in $i.


From your code, you are assigning $i from $info so $i should be the single URL that then gets checked for the keyword.

Having not run the code and seen the formatting, you may need to add $i to $messageboxbody. For example

$Messageboxbody = "Detected the keyword $keyword at $b from URL $i"

Hope this helps.

Thanks, Tim.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.