#21141·PowerShell

Get-ChildItem not throwing consistent errors for path not found

Author: DarkLite1Created Jan 25, 2024Updated Sep 17, 2026
LabelsWG-CmdletsUp-for-GrabsWG-Reviewed

Prerequisites

Steps to reproduce

When working with the Pester test suite we regularly use the default provided drive TestDrive:\ described here.

For one reason or another the error thrown by Get-ChildItem for a Path not found is different depending on the drive used.

$params = @{
    # LiteralPath = 'c:\NotExisting' # Cannot find path 'C:\NotExisting' because it does not exist.
    LiteralPath = 'TestDrive:\NotExisting' # A parameter cannot be found that matches parameter name 'File'.
    File        = $true
    ErrorAction = 'Stop'
}
Get-ChildItem @params

Expected behavior

In all cases where the path is not found, we would expect `Get-ChildItem` to throw the error:

>  Cannot find path 'x:\\\xxx' because it does not exist.

Actual behavior

The actual behaviour is inconsistent depending on the drive.

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Microsoft Windows 10.0.20348
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response