Join-Path : Cannot find drive. A drive with the name 'D' does not exist

Hello guys,

When I run the script, I am getting this error.

Join-Path : Cannot find drive. A drive with the name 'D' does not exist.
At C:\t.ps1:82 char:21
+             $path = Join-Path $_.Path $Product.PackageName
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (D:String) [Join-Path], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.JoinPathCommand

Is there any way that I can change this join-path to avoid the exists check? Any help would be great :slight_smile:

Here is the related script portion:

$test = {
    param (

    if ($Product.PSPath -and ($Product | Test-Path)) {
        return $true

    if ($Product.PackageName) {
        $Product | Get-MSISource | ForEach-Object {
            $path = Join-Path $_.Path $Product.PackageName
            if ($path | Test-Path) {
                Write-Verbose ($loc.Verbose_Found_Source_Args2 -f $Product.ProductCode, $path)
                return $true


Here is the script

Welcome to the forums.

You may start debugging your script by checking the content of the variables during runtime. In the simplest case you just output them to the console. I’d start with $_.Path.

You did not show what Get-MSISource does or outputs. If it returns drive letters without a colon at the end you may add in your code “manually”.

Hello Olaf,

Thanks for your reply. I fix this “cannot find drive” issue by putting USB stick into my computer. Now I have a different case.

Remove-Item : Cannot find path 'HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\03D8475ED6E7E8A3FB6E1C0DC2D6ADBB' because it does not exist.
At C:\t.ps1:100 char:9
+         Remove-Item -Recurse -Force -UseTransaction $Key

Does this try/catch make this script run?

if (Test-Path $Key) {
        Write-Verbose ($loc.Verbose_Remove_Key_Args1 -f $Key)
        Try { Remove-Item -Recurse -Force -UseTransaction $Key } Catch { continue }

:wink: … no you did not!! :wink:

In your initial post you had the error in line 82. I’d recommend to insert the following code line right above the line 82: (actually as the new line 82 and make the old line 82 the new line 83 :wink: )

Write-Host "Content of the variable `$_.Path: '$($_.Path)'" -ForegroundColor Magenta