You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New-Item ignore's Path param if Name param is specified #5228
Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
Set-Location ~
New-Item-Path C:\ -Name Test -ItemType Directory -Verbose
Expected behavior
Test folder created in Root C:\
Actual behavior
Folder created in current path
PS C:\Users\Aftab> New-Item -Path C:\ -Name Test -ItemType Directory -Verbose
VERBOSE: Performing the operation "Create Directory" on target "Destination: C:\Users\Aftab\Test".
Directory: C:\Users\Aftab
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 25/10/2017 13:51 Test
PS C:\Users\Aftab> Get-Item C:\Test
Get-Item : Cannot find path 'C:\Test' because it does not exist.
At line:1 char:1
+ Get-Item C:\Test
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Test:String) [Get-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand
PS C:\Users\Aftab> Get-Item ~\Test
Directory: C:\Users\Aftab
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 25/10/2017 13:51 Test
Environment data
>$PSVersionTable
Name Value
---------
PSVersion 6.0.0-beta.8
PSEdition Core
GitCommitId v6.0.0-beta.8
OS Microsoft Windows 10.0.15063
Platform Win32NT
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
@mcbobke Thanks for your investigation!
It can be tricky - there is some code levels - cmdlet, globbing, provider and some abstractions layers. I suggest you to debug starting with New-Item cmdlet code and compare code paths in your samples.
It looks like the fix for this in #6600 broke some Set-Location behaviour. Fixing this will need to account for Set-Location wanting to restore the path and New-Item wanting to use the path as given. It may be that C: should use the restored path and C:\ should not?
Not really having followed all of this, I'd say you're correct: c: should refer to whatever location is current in that drive, whereas c:\ should refer to the drive's root directory.
Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
Activity
affieuk commentedon Oct 25, 2017
This also occurs in a mounted a vhdx.
iSazonov commentedon Oct 25, 2017
Aftab Hussain (@affieuk) Thanks for your report!
I can confirm that new directory is created in current folder not in
Path.iSazonov commentedon Apr 4, 2018
@mcbobke Thanks for your investigation!
It can be tricky - there is some code levels - cmdlet, globbing, provider and some abstractions layers. I suggest you to debug starting with New-Item cmdlet code and compare code paths in your samples.
iSazonov commentedon Apr 4, 2018
@mcbobke Do you use latest VS Code version?
iSazonov commentedon Apr 5, 2018
@mcbobke Every provider keep own current directory. In FileSystem provider case the currect directory differ from .Net current directory.
iSazonov commentedon Apr 9, 2018
Should we consider other providers too?
/cc Michael Klement (@mklement0)
rjmholt commentedon Apr 27, 2018
It looks like the fix for this in #6600 broke some
Set-Locationbehaviour. Fixing this will need to account forSet-Locationwanting to restore the path andNew-Itemwanting to use the path as given. It may be thatC:should use the restored path andC:\should not?mklement0 commentedon Apr 27, 2018
Rob Holt (@rjmholt):
Not really having followed all of this, I'd say you're correct:
c:should refer to whatever location is current in that drive, whereasc:\should refer to the drive's root directory.That's how it works in
cmd.exetoo.