Power Shell | Skripte


Loop through results from Select-String

Here is an example that greps for a string and uses the results in a loop to determine if some action should be taken

$pattern = "tachytelic"
$files = Select-String -Path "d:\script\*.txt" -Pattern $pattern
foreach ($file in $files) {
    $item = get-item $file.Path
    "File '{0}' matches the pattern '{1}'" -f $item.FullName, $pattern
    "It was last modified on {0}" -f $item.LastWriteTime
  $response = Read-Host -Prompt "Set the archive bit on this file?" 
  If ($response -eq 'Y') {

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

de German