Reputation: 41
Having some issue using basic import-csv in a loop function.
I have basic csv file with hostname, node headers
I am assigning the file using import-csv
Then I am then simply starting foreach
loop when I am trying to test-path using the hostname within unc path \\$r.hostname\c$\users\something\desktop
Expected result is true
But the actual result is false
when I am trying the actual hostname in the test-path instead of the csv param its working just fine.
$records = Import-Csv C:\Users\someuser\Desktop\partition-mapping.csv
foreach ($r in $records)
{
Test-Path -LiteralPath \\$r.hostname\c$\users <<====not working
Test-Path -LiteralPath \\hostname01.lab.local\C$\Users\ <<====== workign fine
}
as always you guys are awesome !!
Upvotes: 2
Views: 4675
Reputation: 72610
Just test :
Test-Path -LiteralPath "\\$($r.hostname)\c$\users" <<====now working ;o)
The trouble comes from the fact that $r
is directly interpreted as a var, so the final string is "\\$r collection as a string.hostname\c$\users"
Upvotes: 2