Test-Path does not find existing path

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:


            $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:


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

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???

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: