I want to make a script. It will read content from a file which recorded path. And run test-path for path in the file to verify if these file/path exists on local machine.
Here is my current powershell code:
Foreach ($path in (get-content C:\temp\pathlist.txt)){
[PSCustomObject]@{
path = $path
Exists = test-path $path
}
}
However, it will always return 'False' even the path exists and even there is only one line in the txt. I also tried -TotalCount to restrict the line it reads. But it failed again.
Besides, actually I would like to do some string process on the txt. The txt in above code just contain normal path. But the acutal txt I would got has a format as: "C:\Windows\","1" I used to use $path= $path.split(",")[0] to get the "C:\windows". But to fix the always 'False' issue, I use a simple txt instead and remove this part in my code.