I'm building a tool that will scan my files and a friend's files. We will use this to make sure we have the same files in our databases. The script I have so far has a variable input issue. For some reason, the PowerShell script fails on my drive letter input. Anyone have any ideas?
Here is my script:
{ function Show-Menu { param ( [string] $Title = "Andy's Manual Database Tool" ) Clear-Host Write-Host "" Write-Host "================ $Title ================" Write-Host "" Write-Host -f Green "1. Andys Files listing" Write-Host -f green "2. Reids files listing" Write-Host -f Red "3. Dark Matter Testing" Write-Host "4. Convert .txt to .csv" Write-Host "5. Convert Blank File to .csv" Write-Host "6. Convert .csv to .txt" } Function Body { Show-Menu Write-Host "" $Input = Read-Host "Please make a selection" if ($Input -eq "1") { Clear-Host $root = Read-Host -Prompt 'Specify the location of Database? Example format: C:\*' $y = read-host -Prompt 'Input file types. Format Example: " .jpg,.mp4,.mp3,.pdf .... " Do * for all' $z = Read-Host -Prompt 'Your Save file name will be? Examples: Movies database , Music database , audiobooks.' Get-ChildItem -Path $root -File -Recurse *.$y | Select-Object -Property Name | Export-Csv -NoTypeInformation $z Andy.csv } if ($Input -eq "2") { Clear-Host $root = Read-Host -Prompt 'Specify the location of Database? Example format: C:\*' $y = read-host -Prompt 'Input file types. File Format Examples: " .jpg,.mp4,.mp3,.pdf .... " Do * for all' $z = Read-Host -Prompt 'Your Save file name will be? Examples: Movies database , Music database , audiobooks.' Get-ChildItem -Path $root -File -Recurse *.$y | Select-Object -Property Name | Export-Csv -NoTypeInformation $z' From Reid.csv' } if ($Input -eq "3") { Get-Process | Stop-Process } if ($Input -eq "4") { Clear-Host Get-ChildItem *.txt | rename-item -newname { $_.name -replace ".txt",".csv" } } if ($Input -eq "5") { Clear-Host Get-ChildItem * -Exclude *.ps1,*.CSV,*.TXT | rename-item -newname { "$($_.name).CSV" } } if ($Input -eq "6") { Clear-Host Get-ChildItem *.csv | rename-item -newname { $_.name -replace ".csv",".txt" } } Write-Host 'Complete! ^_^' Start-Sleep -seconds 5 Body } Body } This issue is here, from the script above:
$root = Read-Host -Prompt 'Specify the location of Database? Example format: C:\*' $y = read-host -Prompt 'Input file types. Format Example: " .jpg,.mp4,.mp3,.pdf .... " Do * for all' $z = Read-Host -Prompt 'Your Save file name will be? Examples: Movies database , Music database , audiobooks.' Get-ChildItem -Path $root -File -Recurse *.$y | Select-Object -Property Name | Export-Csv -NoTypeInformation $z Andy.csv I'm using $root as an input for my drive letter or location path which is the problem.
$Input