Get-ChildItem -Path D:\Users |
ForEach-Object{
$abc_exist = test-path -path "D:\Users\$_\Favorites\AB C D.url"
if ($abc_exist){
try{
-- some actions
}
}
}
Dear all,
I can make the script worked by try-and-error approach.
At first, I used
$abc_exist = test-path -path "D:\Users\$_.name\Favorites\AB C D.url"
But it didn’t work. I use “Write-out” and find out that the path will look like “D:\Users\Myusername.name\Favorities\AB C D.url” this in the output.
Then I just leave $_ in the code and now it works. As I thought, after get-childitem pipe, the whole object will be moved to the next action “ForEach_Object”. I thought I need to specify the property “Name” instead of leaving the whole object in the file path.
Did I have the wrong concept about this? Many thanks for the newbie question.