Forum Discussion
user4444
Jan 26, 2022Copper Contributor
Get-ChildItem & Write-Host - output missing
I've created a simple script to search for a folder (study) in a list of locations. This has been working ok during testing, but I ocassionally encounter a issue where the output doesn't output the p...
- Jan 26, 2022
You have to enclose the variable and use .fullname behind it, you can see the options if you enter $study_dirs after you run the script
# Prompt user for study number $study = Read-Host -Prompt 'Enter the study number to search for...' # Create variable with value containing a list of study locations. $study_paths = Get-Content -Path 'E:\pshell-testing\locations2.txt' # Define recursion depth $rec_depth = 3 # Begin searching foreach ($study_path in $study_paths) { $study_dirs = Get-ChildItem -Directory -Force -ErrorAction SilentlyContinue -Recurse -Depth $rec_depth -Path $study_path | Where-Object {$_.Name -match $study} | Select-Object -Property FullName if (!$study_dirs) { Write-Host -ForegroundColor Yellow "No studies found in $study_path" } elseif ($study_dirs) { Write-Host -ForegroundColor Green "Study $study found. Location - $($study_dirs.Fullname)" } }
user4444
Jan 27, 2022Copper Contributor
Hello Harm_Veenstra,
thank you for your reply and help.
The amendments you've suggest do improve the script. Where I wasn't receiving the path I now do. However, I now receive it twice? I've tried some variations of your amendment, but I've not been able to get the output to only show the path once.
This isn't big issue, at least I am able to see the path, but it would be good know why I'm seeing it twice?
Example output:
Study 12345 found. Location - \\File-Server1\e$\folder1\F2\f3\12345 \\File-Server1\e$\folder1\F2\f3\12345
thank you for your reply and help.
The amendments you've suggest do improve the script. Where I wasn't receiving the path I now do. However, I now receive it twice? I've tried some variations of your amendment, but I've not been able to get the output to only show the path once.
This isn't big issue, at least I am able to see the path, but it would be good know why I'm seeing it twice?
Example output:
Study 12345 found. Location - \\File-Server1\e$\folder1\F2\f3\12345 \\File-Server1\e$\folder1\F2\f3\12345
user4444
Jan 27, 2022Copper Contributor
Actually, ignore my last reply.
I think I've spotted the issue...its me 🙂 I think there are two folders of the same name being found on the same path, one is in a subdirectory. This is actually better than I expected.
Thank you.
I think I've spotted the issue...its me 🙂 I think there are two folders of the same name being found on the same path, one is in a subdirectory. This is actually better than I expected.
Thank you.
- Jan 27, 2022Ah, good to hear 🙂