title: Batch to PowerShell Language Conversion
body: <p>My batch script in DOS is processing way to slow, so someone recomended I use powershell. I'm running it now for my first time on windows, but I've never used it before today. I hear it's similar to batch scripting, so I'm currently converting my batch script into a powershell script. Below is my script so far half way through conversion: </p>
  
  <pre><code># ask user for network share and file that they would like to search
  $textFilePath = Read-Host Please enter filesystem location of "filenames.txt". Include drive letter or // at start of path
  $uncPath = Read-Host Please enter the UNC path you would like to search. Include // at start of path.
  
  # REM check if network path is available. If it is, search network directory for files with same name as the strings in filenames.txt
  IF (Test-Path %uncPath%) {
      echo Network Path Exists. Searching %uncPath% for files with same name and extension as filenames in the filenames.txt file 
      for (/r %uncPath% %%G IN (*)) {for (/F "tokens=*" %%i in (%textFilePath%)) {if (%%~nxG==%%i) {echo %%~nxG,%%~fG &gt;&gt; filenamesOutput.txt}}}
      pause
  }
  
  IF (!(Test-Path exist %uncPath%)) {
      echo File not found
      GOTO:userInput
  }
  </code></pre>
  
  <p>I'm currently learning the powershell commands as I go and changing the batch command to powershell. Help with conversion would be appreciated.</p>
  
  <p>AFter Edit:</p>
  
  <p>Here's my original batch script:</p>
  
  <pre><code>@echo off
  
  echo Please enter filesystem location of "filenames.txt". (Include Drive letter or // at start of path)
  set /p textFilePath=Enter The Value:%=%
  :userInput
  REM ask user for network share and file that they would like to search
  echo Please enter the UNC path you would like to search. (Include // at start of path)
  set /p uncPath=Enter The Value:%=%
  
  REM check if network path is available. If it is, search network directory for files with same name as the strings in filenames.txt
  IF exist %uncPath% (
      echo Network Path Exists. Searching %uncPath% for files with same name and extension as filenames in the filenames.txt file
      for /r %uncPath% %%G IN (*) DO for /F "tokens=*" %%i in (%textFilePath%) DO if %%~nxG==%%i echo %%~nxG,%%~fG &gt;&gt; filenamesOutput.txt
      pause
  )
  
  IF NOT exist %uncPath% (
      echo File not found
      GOTO:userInput
  )
  </code></pre>
  
  <p>After 2nd Edit:</p>
  
  <pre><code>$VerbosePreference = "continue"
  
  # ask user for network share and file that they would like to search
  $textFilePath = Read-Host Please enter filesystem location of     "filenames.txt". Include drive letter or // at start of path
  $uncPath = Read-Host Please enter the UNC path you would like to search. Include // at start of path.
  
  # check if network path is available. If it is, search network directory for     files with same name as the strings in filenames.txt
  IF (Test-Path $uncPath){
      echo "Network Path Exists. Searching $uncPath for files with same name and extension as filenames in the filenames.txt file"
      foreach($file in Get-ChildItem $uncPath -Recurse) {
          # Get-Content reads in a file, line by line
          foreach($line in Get-Content $_.FullName) {
              # if goes in here
              if($file.Name -eq $line){
                  echo $file.Name
                  "{0},{1}" -f $file.Name,$file.FullName | Out-File filenamesOutput2.txt -Append
              }
          }
      }
  Write-Host -NoNewLine 'Press any key to continue...';
  $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
  }
  
  
  
  IF (!(Test-Path $uncPath)){
      echo "UNC path not found"
      Write-Host -NoNewLine 'Press any key to continue...';
      $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
  }
  </code></pre>