Powershell: New-TemporaryFile returns a object without extended filesystem provider properties

Created on 13 Sep 2017  路  9Comments  路  Source: PowerShell/PowerShell

New-TemporaryFile returns a native .Net FileInfo object without extended PowerShell filesystem provider properties.

The problem is in PowerShell Core 6 but not in Windows PowerShell.

Steps to reproduce

$temp =  New-TemporaryFile
$temp | Select-Object PS*

Expected behavior

PSPath        : Microsoft.PowerShell.Core\FileSystem::C:\Users\username\AppData\Local\Temp\tmpE88E.tmp
PSParentPath  : Microsoft.PowerShell.Core\FileSystem::C:\Users\username\AppData\Local\Temp
PSChildName   : tmpE88E.tmp
PSDrive       : C
PSProvider    : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False

Actual behavior

<empty>

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-beta
PSEdition                      Core
GitCommitId                    v6.0.0-beta.6-60-g4ad313aafb1a1b747aaec0f975dcc823e4c907fc-dirty
OS                             Microsoft Windows 10.0.10240
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Area-Cmdlets-Utility Issue-Bug

All 9 comments

I don't see how we can fix this in a simple way so maybe Won't fix.

One way to fix this is to call Get-Item on it and the FileSystemProvider will decorate it and return that object.

@SteveL-MSFT I tried to do it, but I was having troubles. (1) We should create GetItemCommand for every new temp file - it seems looks not good. (2) I can not create GetItemCommand in the New-TemporaryFile cmdlet - unresolved name. If we have to add reference from Utility assembly to Management assembly - it seems looks not good?

Maybe this is an opportunity to revisit https://github.com/PowerShell/PowerShell/issues/4347#issuecomment-318098122 (making these properties part of the ETS rather than having the filesystem provider add it)?

@mklement0 yes, I think doing this as part of ETS makes sense, perhaps we should resolve this as dupe of that one

Good catch about ETS! Thanks!

What is right place for the fix?

@SteveL-MSFT:

Glad to hear it.

Re dupe:

Given that #4347 was just framed as a _question_, I suggest creating a new, focused issue that reflects the intent to actually implement this (note that @lzybkr's original comments suggest that there may be conceptual problems).

@iSazonov:

From what I can tell, the relevant ETS members are defined here:

System.IO.FileInfo:

https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/Types_Ps1Xml.cs#L192

System.IO.DirectoryInfo:

https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/Types_Ps1Xml.cs#L180

@mklement0 Thanks for clarify!

I'm afraid I don't see all the side effects. Maybe @jeffbi can fix this?

@iSazonov @jeffbi was a vendor we hired to do some work, he's no longer on the project unless he wants to contribute personally

Was this page helpful?
0 / 5 - 0 ratings