0 like 0 dislike
2 views
in Bilgi Teknolojileri by anonymous
powershell ile klasör arama

1 Answer

0 like 0 dislike
by anonymous
$searchselection = Read-Host -Prompt 'Belirli bir makinede aramak istiyorsaniz 1, belirli bir makine grubunu (orn: FINANS veya MUHASEBE) aramak istiyorsaniz 2, tum makineleri aramak istiyorsaniz 3 yaziniz.'

if (1 -eq $searchselection) {

    Write-Host "Arama sonucunu C:\belirliklasorbulma.csv dosyasinda bulabilirsiniz. Dosyayı kontrol etmek icin aramanin bitmesini bekleyiniz."

    $pcname = Read-Host -Prompt 'Aramak istediginiz makine ismini giriniz (orn: MUHASEBE100DESKTOP)'

    $searchfolderonepc = Read-Host -Prompt 'Aramak istediginiz klasor ismini giriniz'

    $computer = Get-ADComputer -Identity $pcname

    

    $PC = $computer.dnshostname

    if (Test-Connection $pc -Count 1 -Quiet -BufferSize 1) {

        Write-Host " "

        Write-Host "$pc makinesi taraniyor..."

        Write-Host " "

$UserListPath = @()

        $UsersPath = "\\$pc\c$\Users\"

$UserListPath += Get-ChildItem -Path $UsersPath | foreach {$_.FullName}

$Constant = "\AppData"

        $ConcateStrings = foreach ($AppData in $UserListPath) {

            "$AppData$Constant"

        }

        foreach ($i in $ConcateStrings) {

            Write-Host "$i ve alt dizinleri taranacak..."

        }

        Write-Host " "

foreach ($SearchFolder in $ConcateStrings) {

            Write-Host "$SearchFolder ve alt dizinleri taraniyor..."

Get-ChildItem $SearchFolder -Recurse -ErrorAction SilentlyContinue -Force | Where-Object {$_.PSIsContainer -eq $true -and $_.Name -match $searchfolderonepc} | export-csv –append –path C:\belirliklasorbulma.csv

            $count = (Get-ChildItem $SearchFolder -Recurse -ErrorAction SilentlyContinue -Force | Where-Object {$_.PSIsContainer -eq $true -and $_.Name -match $searchfolderonepc} | Measure-Object).Count

            if (0 -eq $count) {

                Write-Host "Klasor bulunamadi."

                Write-Host " "

            }

            else {

                Write-Host "$count adet bulundu."

                Write-Host " "

            }

}

}

}

elseif (2 -eq $searchselection) {

    Write-Host "Arama sonucunu C:\belirliklasorbulma.csv dosyasinda bulabilirsiniz. Dosyayı kontrol etmek icin aramanin bitmesini bekleyiniz."

    $pcgroupname = Read-Host -Prompt 'Aramak istediginiz makine grubunu giriniz (orn: URETIM veya MUHASEBE)'

    $searchfolderpcgroups = Read-Host -Prompt 'Aramak istediginiz klasor ismini giriniz'

    $Computers = Get-ADComputer -Filter "Name -like '$pcgroupname*'"

    foreach ($Computer in $Computers) {

    $PC = $computer.dnshostname

        if (Test-Connection $pc -Count 1 -Quiet -BufferSize 1) {

            Write-Host " "

            Write-Host "$pc makinesi taraniyor..."

            Write-Host " "

    $UserListPath = @()

            $UsersPath = "\\$pc\c$\Users\"

    $UserListPath += Get-ChildItem -Path $UsersPath | foreach {$_.FullName}

    $Constant = "\AppData"

            $ConcateStrings = foreach ($AppData in $UserListPath) {

                "$AppData$Constant"

            }

            foreach ($i in $ConcateStrings) {

                Write-Host "$i ve alt dizinleri taranacak..."

            }

            Write-Host " "

    foreach ($SearchFolder in $ConcateStrings) {

                Write-Host "$SearchFolder ve alt dizinleri taraniyor..."

    Get-ChildItem $SearchFolder -Recurse -ErrorAction SilentlyContinue -Force | Where-Object {$_.PSIsContainer -eq $true -and $_.Name -match $searchfolderpcgroups} | export-csv –append –path C:\belirliklasorbulma.csv

                $count = (Get-ChildItem $SearchFolder -Recurse -ErrorAction SilentlyContinue -Force | Where-Object {$_.PSIsContainer -eq $true -and $_.Name -match $searchfolderpcgroups} | Measure-Object).Count

                if (0 -eq $count) {

                    Write-Host "Klasor bulunamadi."

                    Write-Host " "

                }

                else {

                    Write-Host "$count adet bulundu."

                    Write-Host " "

                }

    }

    }

    }

}

elseif (3 -eq $searchselection) {

    Write-Host "Arama sonucunu C:\belirliklasorbulma.csv dosyasinda bulabilirsiniz. Dosyayı kontrol etmek icin aramanin bitmesini bekleyiniz."

    $searchselectionallpcsure = Read-Host -Prompt 'Tum makinelerde arama yapilacaktir. Bu islem uzun surecektir. Emin misiniz? E/H'

    if ("E" -eq $searchselectionallpcsure) {

        $searchfolderallpcs = Read-Host -Prompt 'Aramak istediginiz klasor ismini giriniz'

        $Computers = Get-Adcomputer -Filter *

        foreach ($Computer in $Computers) {

        $PC = $computer.dnshostname

            if (Test-Connection $pc -Count 1 -Quiet -BufferSize 1) {

                Write-Host " "

                Write-Host "$pc makinesi taraniyor..."

                Write-Host " "

        $UserListPath = @()

                $UsersPath = "\\$pc\c$\Users\"

        $UserListPath += Get-ChildItem -Path $UsersPath | foreach {$_.FullName}

        $Constant = "\AppData"

                $ConcateStrings = foreach ($AppData in $UserListPath) {

                    "$AppData$Constant"

                }

                foreach ($i in $ConcateStrings) {

                    Write-Host "$i ve alt dizinleri taranacak..."

                }

                Write-Host " "

        foreach ($SearchFolder in $ConcateStrings) {

                    Write-Host "$SearchFolder ve alt dizinleri taraniyor..."

        Get-ChildItem $SearchFolder -Recurse -ErrorAction SilentlyContinue -Force | Where-Object {$_.PSIsContainer -eq $true -and $_.Name -match $searchselectionallpcsure} | export-csv –append –path C:\belirliklasorbulma.csv

                    $count = (Get-ChildItem $SearchFolder -Recurse -ErrorAction SilentlyContinue -Force | Where-Object {$_.PSIsContainer -eq $true -and $_.Name -match $searchselectionallpcsure} | Measure-Object).Count

                    if (0 -eq $count) {

                        Write-Host "Klasor bulunamadi."

                        Write-Host " "

                    }

                    else {

                        Write-Host "$count adet bulundu."

                        Write-Host " "

                    }

        }

        }

        }

    }

    elseif ("H" -eq $searchselectionallpcsure) {

        Write-Host 'Arama iptal edildi.'

    }

    else {

    Write-Host "Gecersiz bir secim yaptiniz. Tekrar deneyiniz."

    }

}

else {

    Write-Host "Gecersiz bir secim yaptiniz. Tekrar deneyiniz."

}
En güncel teknolojiler hakkında yeni şeyler öğren, bilmediklerini sor, bildiklerini paylaş...

Categories

...