2

Having some issue using basic import-csv in a loop function.

  1. I have basic csv file with hostname, node headers

  2. I am assigning the file using import-csv

  3. 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

  4. Expected result is true

  5. 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 !!

1 Answer 1

2

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"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.