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

**URL:** <https://forums.powershell.org/t/join-path-cannot-find-drive-a-drive-with-the-name-d-does-not-exist/16728>\
**Category:** PowerShell Help\
**Created:** [June 3, 2021, 11:11am UTC](https://forums.powershell.org/t/join-path-cannot-find-drive-a-drive-with-the-name-d-does-not-exist/16728 "2021-06-03T11:11:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cenk](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@Cenk](https://forums.powershell.org/u/Cenk)\
**Post date:** [June 3, 2021, 11:11am UTC](https://forums.powershell.org/t/join-path-cannot-find-drive-a-drive-with-the-name-d-does-not-exist/16728/1 "2021-06-03T11:11:51Z")

</div>

Hello guys,

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

```auto
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 🙂

Here is the related script portion:

```auto
$test = {
    param (
        $Product
    )

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

    $false
}

```

[Here is the script](https://gist.github.com/NikitaGolovko/1d1f648ce914c1e91e23a9860a24aaa7)

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 3, 2021, 12:41pm UTC](https://forums.powershell.org/t/join-path-cannot-find-drive-a-drive-with-the-name-d-does-not-exist/16728/2 "2021-06-03T12:41:02Z")

</div>

Cenk,  
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_”.

---

<div class="post-metadata">

**Author:** ![Cenk](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@Cenk](https://forums.powershell.org/u/Cenk)\
**Post date:** [June 3, 2021, 1:27pm UTC](https://forums.powershell.org/t/join-path-cannot-find-drive-a-drive-with-the-name-d-does-not-exist/16728/3 "2021-06-03T13:27:05Z")

</div>

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.

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

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

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 3, 2021, 1:44pm UTC](https://forums.powershell.org/t/join-path-cannot-find-drive-a-drive-with-the-name-d-does-not-exist/16728/4 "2021-06-03T13:44:38Z")

</div>

> [@Cenk](#):
>
> I fix this “cannot find drive” issue

😉 … no you did not!! 😉

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 😉 )

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

```

---

<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:24pm UTC](https://forums.powershell.org/t/join-path-cannot-find-drive-a-drive-with-the-name-d-does-not-exist/16728/5 "2024-05-16T20:24:21Z")

</div>


