Hi there,
i’m currently running a script that will check certain websites (own hosted & owned) for some keywords but it is not that fast. Maybe you have an idea how to speed this a bit up.
Hmmm … your code looks convoluted and confusing to me. How does your $KeywordList look like? And what output would you expect? How about using Select-String?
You could have mentioned that before. If you want to know where in script the bottle neck is you should measure it. I’d assume the Invoke-WebRequest takes some time. And if you have more than one you’re pretty much out of luck if you cannot speed this up.
Hey Olaf,
looks good - thanks for that. But one other question. Does it make sense to check the site if a specific word from the list was detected word by word in this way?
$Keywordlist=@("word1","word2","word3")
$SiteContent = (Invoke-WebRequest $SiteLoc -UseBasicParsing -Headers @{"Cache-Control" = "no-cache" }).Content
if ($SiteContent | Select-String -Pattern $Keywordlist){
# one of the words where found
foreach ($word in $Keywordlist){
$WordWasFound = ($SiteContent | Select-String -Pattern $word)
if ($WordWasFound){
# add it to list
}
}
}
else {
# move on to next site
continue
}
That’s a question only you can answer. I’d probably use the output Select-String already provides and parse this instead of running it again and again and again for every single keyword.
But how should I then now if one specify word was found on the site?
If I’ll do it this way then i do a previous check and if it is existing on this site then I need to check for the specific word or do you know a better way?
The output of Select-String contains information about all found patterns, their line number, the complete line it was found on and some more if you like. I’d use this output for further steps rather than running Select-String on each individual key word again - that’s what I meant.
Then you will get an output of the whole HTML file not only the found patterns and I think that is my problem because I couldn’t see if the pattern has been found.