none
multiple values in read host RRS feed

  • Question

  • Hi 

    I am using following code to filter specific folders using read host  command. How can I put multiple folder in read-host input as I have multiple folder names to filter? Thanks


    #This is what Directory you want to search
    $searchDir = Read-Host "C:\Users\admin\Desktop\dir2dir"

    #This is what folder, you're searching for
    $searchFolder = Read-Host "folderA, folderB, folderC"

    #This is the location of your logfile of results if you choose to
    #have the results written to the logfile (uncomment the line below)
    $outputDir = "C:\scripts\files_$(get-date -f yyyy-MM-dd).csv"
    $files = Get-ChildItem -Path $searchDir -Recurse -Filter $searchFile -EA silentlyContinue | Select Fullname, @{Name="MegaBytes"; Expression={"{0:F2}" -f ($_.Length / 1MB)}}, CreationTime, LastAccessTime | Sort-Object MegaBytes -Descending

    #The results output to a CSV file
    $files | Export-Csv $outputDir

    write-host -foregroundcolor yellow "Search complete, results can be viewed here: $outputDir"

    #Start excel and open the logfile of the results
    Start-Process Excel -ArgumentList $outputDir

    • Moved by Bill_Stewart Wednesday, September 4, 2019 9:40 PM This is not "teach me basics" forum
    Tuesday, April 30, 2019 8:33 PM

All replies

  • Code similar to below should work, if the values are provided comma delimited.

    $Input = Read-Host "Enter folder names, comma delimited"
    $Folders = $Input -Split ","
    $Results = @()
    ForEach ($Folder In $Folders)
    {
        $Results += New-Object PsObject -Property @{
            Folder = $Folder
        }
    }
    
    $Results | Export-Csv Test173.csv -NoTypeInfo
    


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Tuesday, April 30, 2019 8:58 PM
  • hi

    Actually my objective is to find the path of all those specific folders in csv so will this code just search the folders or also give me the path in csv?

    Tuesday, April 30, 2019 10:07 PM