Snippets

Ettar Powershell Find-File

Created by Ettar last modified
$cleanRet = $false #Auf True setzen, wenn die Textdatei jedesmal gelöscht werden soll
$searchGo = $true
$searchpath = "" #Hier den Suchpfad angeben

if(!(Test-Path .\Filelist.txt)){
    Write-Host "Dateiliste nicht gefunden"
    $searchGo = $false
}
if(!(Test-Path $searchpath)){
    Write-Host "Suchpfad nicht verfügbar"
    $searchGo = $false
}
if($cleanRet){
    Remove-Item .\return.txt
}


if($searchGo){

    if(!(Test-Path .\return.txt)){
        New-Item -Name "return.txt" -Path .\ -ItemType File
    }

    $list = Get-Content .\Filelist.txt #ATM liegt die Filelist im gleichen Ordner, wie das Skript
    foreach($item in $list) {
        $name = $item.Split(".")
        $name = $name[0]
        $file = Get-ChildItem -Recurse -Path $searchpath | where{$_.Name -like "$name*"  -and !$_.PSIsContainer}
        Add-Content -Path .\return.txt -Value $file.FullName
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.