2

I need to verify one path using powershell. The problem is when given the path like Test-Path -Path "\\\10.2.200.13\share\Logger\Logger" its working fine, but my requirement is that, this path will be available in a Notepad - we need to read the path from the notepad then verify it. Here is the code:

$var = ( Get-Content D:\TestPathIssue\Params.txt ) -split '='
$source1=$var[1].Trim();
test-path -Path $source1;

I am able to get path in $source1 but I don't understand why its failing in Test-Path in this approach.

1
  • When you say Notepad do you really mean you need to get the path from a file? Commented Feb 3, 2015 at 10:15

3 Answers 3

3

Fixed by trying this-

$source1=$source1 -replace '"', ""
Sign up to request clarification or add additional context in comments.

Comments

0

Check if the variable $source1 is returning path in quotes eg:- "\10.2.200.13\share\Logger\Logger" instead of \10.2.200.13\share\Logger\Logger

1 Comment

I am getting "\\10.2.200.13\share\Logger\Logger" in variable $source1
0

The following powershell code will take a list of legal characters with regex and report back on any non-legal characters found in filenames. Modify the list of legal characters as desired.

$legal = "[a-zA-Z\d\.\-'_\s\(\)&,%\[\];\!\$\+@~=#]"

ForEach ($File in Get-ChildItem -Path C:\mypath -Recurse){
  ForEach ($char in $File.Name.ToCharArray()){
    If ($char -notmatch $legal){
      $output = $char+" found in "+$file.fullname
      write-output $output
      break
    }  
  }
}

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.