# Test-Path does not find existing path

**URL:** <https://forums.powershell.org/t/test-path-does-not-find-existing-path/3821>\
**Category:** PowerShell Help\
**Created:** [March 3, 2015, 8:37pm UTC](https://forums.powershell.org/t/test-path-does-not-find-existing-path/3821 "2015-03-03T20:37:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![openiduser1](https://avatars.discourse-cdn.com/v4/letter/o/ea5d25/32.png) [@openiduser1](https://forums.powershell.org/u/openiduser1)\
**Post date:** [March 3, 2015, 8:37pm UTC](https://forums.powershell.org/t/test-path-does-not-find-existing-path/3821/1 "2015-03-03T20:37:53Z")

</div>

Hi all

I am developing a script that shall run on our server. On my laptop, it works just fine but on the server Test-Path does not find an existing path. The failing snipped is with the Test-Path on line 5:

```auto

            $serverInformaticaBinDirectoryPathString = `
               'D:\localapps\informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities\PC\server\bin'
            $workstationInformaticaBinDirectoryPathString = `
               'C:\Informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities\PC\server\bin'
            if (Test-Path -Path $serverInformaticaBinDirectoryPathString) {
                  [String]$informaticaBinDirectoryPathString = `
                     $serverInformaticaBinDirectoryPathString
            } elseif (
                  Test-Path -Path $workstationInformaticaBinDirectoryPathString
            ) {
                  [String]$informaticaBinDirectoryPathString = `
                     $workstationInformaticaBinDirectoryPathString
            } else {
                  assert-fatal(
                        "I did not find the path to the PowerCenter binaries." +
                        "I looked at following locations:`n" +
                        " $serverInformaticaBinDirectoryPathString`n" +
                        " $workstationInformaticaBinDirectoryPathString")
                  [String]$longestPath = get-longestpath(
                        $serverInformaticaBinDirectoryPathString)
                  assert-fatal(
                        'Longest existing path in "' +
                           $serverInformaticaBinDirectoryPathString + '" is "' +
                           $longestPath + '"')
                  $longestPath = get-longestpath(
                        $workstationInformaticaBinDirectoryPathString)
                  assert-fatal(
                        'Longest existing path in "' +
                           $workstationInformaticaBinDirectoryPathString +
                           '" is "' + $longestPath + '"')
                  exit 1
            }

```

get-longestpath function is defined in a module as follows:

```auto

function get-longestpath {
      param(
            [Parameter(
                  Mandatory=$false,
                  HelpMessage='Path string of which only the directory name shall be returned')]
               [String]$path = ''
      )

      if ($path -ne '') {
            for(
                  $tmpPath = $path;
                  $tmpPath -ne '' -and (-not $longestPath);
                  $tmpPath = Split-Path $tmpPath -Parent
            ) {
                  assert-debug('$tmpPath: ' + $tmpPath)
                  if (Test-Path -Path $tmpPath) {
                        assert-debug('$tmpPath: ' + $tmpPath)
                        $longestPath = $tmpPath
                  }
            }
            $longestPath
      } else {
            ''
      }
}

```

The output of the failing server run is:

> 2015-03-04 09:04:54,739 DEBUG [?.CallSite.Target(:0)] - scriptName: start\_SDMX\_object\_processing
> 
> 2015-03-04 09:04:54,784 FATAL [?.CallSite.Target(:0)] - I did not find the path  
> to the PowerCenter binaries.I looked at following locations:  
> D:\localapps\informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities\PC\server\bin  
> C:\Informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities\PC\server\bin
> 
> 2015-03-04 09:04:54,801 DEBUG [?.CallSite.Target(:0)] - $tmpPath: D:\localapps\informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities\PC\server\bin
> 
> 2015-03-04 09:04:54,812 DEBUG [?.CallSite.Target(:0)] - $tmpPath: D:\localapps\informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities\PC\server
> 
> 2015-03-04 09:04:54,820 DEBUG [?.CallSite.Target(:0)] - $tmpPath: D:\localapps\informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities\PC
> 
> 2015-03-04 09:04:54,825 DEBUG [?.CallSite.Target(:0)] - $tmpPath: D:\localapps\informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities
> 
> 2015-03-04 09:04:54,831 DEBUG [?.CallSite.Target(:0)] - $tmpPath: D:\localapps\informatica\9.5.1\clients\PowerCenterClient
> 
> 2015-03-04 09:04:54,836 DEBUG [?.CallSite.Target(:0)] - $tmpPath: D:\localapps\informatica\9.5.1\clients
> 
> 2015-03-04 09:04:54,842 DEBUG [?.CallSite.Target(:0)] - $tmpPath: D:\localapps\informatica\9.5.1
> 
> 2015-03-04 09:04:54,847 DEBUG [?.CallSite.Target(:0)] - $tmpPath: D:\localapps\informatica
> 
> 2015-03-04 09:04:54,852 DEBUG [?.CallSite.Target(:0)] - $tmpPath: D:\localapps
> 
> 2015-03-04 09:04:54,858 DEBUG [?.CallSite.Target(:0)] - $tmpPath: D:\
> 
> 2015-03-04 09:04:54,868 FATAL [?.CallSite.Target(:0)] - Longest existing path in “D:\localapps\informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities\PC\server\bin” is “”
> 
> 2015-03-04 09:04:54,873 DEBUG [?.CallSite.Target(:0)] - $tmpPath: C:\Informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities\PC\server\bin
> 
> 2015-03-04 09:04:54,880 DEBUG [?.CallSite.Target(:0)] - $tmpPath: C:\Informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities\PC\server
> 
> 2015-03-04 09:04:54,885 DEBUG [?.CallSite.Target(:0)] - $tmpPath: C:\Informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities\PC
> 
> 2015-03-04 09:04:54,891 DEBUG [?.CallSite.Target(:0)] - $tmpPath: C:\Informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities
> 
> 2015-03-04 09:04:54,896 DEBUG [?.CallSite.Target(:0)] - $tmpPath: C:\Informatica\9.5.1\clients\PowerCenterClient
> 
> 2015-03-04 09:04:54,903 DEBUG [?.CallSite.Target(:0)] - $tmpPath: C:\Informatica\9.5.1\clients
> 
> 2015-03-04 09:04:54,909 DEBUG [?.CallSite.Target(:0)] - $tmpPath: C:\Informatica\9.5.1
> 
> 2015-03-04 09:04:54,915 DEBUG [?.CallSite.Target(:0)] - $tmpPath: C:\Informatica
> 
> 2015-03-04 09:04:54,922 DEBUG [?.CallSite.Target(:0)] - $tmpPath: C:\
> 
> 2015-03-04 09:04:54,928 DEBUG [?.CallSite.Target(:0)] - $tmpPath: C:\
> 
> 2015-03-04 09:04:54,938 FATAL [?.CallSite.Target(:0)] - Longest existing path in “C:\Informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities\PC\server\bin” is "C:"

When I `Test-Path -Path D:\localapps\informatica\9.5.1\clients\PowerCenterClient\CommandLineUtilities\PC\server\bin` the output is True

---

<div class="post-metadata">

**Author:** ![openiduser1](https://avatars.discourse-cdn.com/v4/letter/o/ea5d25/32.png) [@openiduser1](https://forums.powershell.org/u/openiduser1)\
**Post date:** [March 3, 2015, 9:37pm UTC](https://forums.powershell.org/t/test-path-does-not-find-existing-path/3821/2 "2015-03-03T21:37:32Z")

</div>

Ok, some more findings.

Test-Path on the server for the path on D (C does not exist there) succeeds within the main script but fails within the module???

---

<div class="post-metadata">

**Author:** ![openiduser1](https://avatars.discourse-cdn.com/v4/letter/o/ea5d25/32.png) [@openiduser1](https://forums.powershell.org/u/openiduser1)\
**Post date:** [March 4, 2015, 12:06am UTC](https://forums.powershell.org/t/test-path-does-not-find-existing-path/3821/3 "2015-03-04T00:06:40Z")

</div>

I traced down to that, independently of main script or module, Get-PSDrive does not show the D drive until there has been an access to from within the script, e.g. by Get-Item D:

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:46pm UTC](https://forums.powershell.org/t/test-path-does-not-find-existing-path/3821/4 "2024-05-16T20:46:18Z")

</div>


