I am very new to powershell and am just beginning to learn the depth of this progrm. My problem is I am getting a ton of information that I am having trouble grasping all of it and so many conflicting methods I am getting lost. This is what I have tried so far and the error message I am getting. If anyone can tell me what I am doing wrong and at least give a hint on how to fix it I would be very happy. Thanks in advance.
Script
$PlaylistName = Read-Host 'Playlist filename (Include drive and path):'
$Directory = Read-Host 'Target Directory (Include drive and path):'
Write-Host "Searching "$PlaylistName" for media files and copying to "$Directory"`n"
Get-Content $PlaylistName | where {$+.trim() -ne "" } | Out-File Temp.txt
get-content Temp.txt | select-string -pattern "#EXTINF:0" -notmatch | Out-File Musiclist.txt
The playlist is here: https://gist.github.com/zipster1967/ddc5ce0d81e70f3e59cf0dfb2b224704
When I run this script I get the following error message and I am not sure what it means.
At line:4 char:44 + Get-Content $PlaylistName | where {$+.trim() -ne "" } | Out-File Temp ... + ~ An expression was expected after '('. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : ExpectedExpression
The Line
Get-Content $PlaylistName | where {$+.trim() -ne "" } | Out-File Temp.txt
I got from http://www.pixelchef.net/remove-empty-lines-file-powershell
Okay based on the suggestions I now have a partially working script. I got all the files into a text file called Temp.txt using the script as follows:
$PlaylistName = Read-Host 'Playlist filename (Include drive and path):'
$Directory = Read-Host 'Target Directory (Include drive and path):'
Write-Host "Searching "$PlaylistName" for media files and copying to "$Directory"`n"
Get-Content $PlaylistName | ? { $_ -and (Test-Path $_) } | Out-File Temp.txt
Now I just have to understand how to get the copy-item command to read the Temp.txt file and copy the files into the $Directory folder. My guess is I need to add the line
Get-Content Temp.txt | Copy-Item -Destination $Directory
I hope that is correct. (Still have a lot to learn in PowerShell.)