Skip to content

Add ability to create a temporary file with a specific extension to New-TemporaryFile #4215

Closed

Description

Related: #3442

Currently, New-TemporaryFile invariably creates temp. files with extension .tmp.

Sometimes, however, it is helpful to create temp. files with a specific filename extension.

Adding an -Extension parameter could provide that:

Desired behavior

> New-TemporaryFile -Extension .ps1

    Directory: C:\Users\jdoe\AppData\Local\Temp

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        7/10/2017   9:53 PM              0 tmpE3B8.ps1

Environment data

PowerShell Core v6.0.0-beta.3

Activity

  1. iSazonov commented on Jul 11, 2017

    @iSazonov
    Collaborator

    What practical scenarios exist when do we need to change the extention?

  2. mklement0 commented on Jul 11, 2017

    @mklement0
    ContributorAuthor

    Whenever you need to create a temporary file to be processed by a utility that requires a specific filename extension.

    Using PowerShell itself as an example, say you want to create a throw-away script dynamically, whose path you want to pass to another PowerShell instance via the CLI (powershell -File ...).
    Such a throw-away script only works if it has extension *.ps1.

  3. SteveL-MSFT commented on Jul 13, 2017

    @SteveL-MSFT
    Member

    Michael Klement (@mklement0) with a recent PR, if you use -File, it doesn't have to have a .ps1 extension :)

  4. mklement0 commented on Jul 13, 2017

    @mklement0
    ContributorAuthor

    Steve Lee (@SteveL-MSFT): Good point; I should have used a different example, such as *.csv for files to be processed by Excel, for instance.

  5. added this to the milestone on Jul 24, 2017
  6. added
    Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributors
    on Jul 24, 2017
  7. bergmeister commented on Aug 18, 2017

    @bergmeister
    Contributor

    I opened the pull request above for it. Please ignore the commits above except for the last one as I squashed the commits in my branch into one commit at the end.

  8. 12 remaining items

  9. AspenForester commented on Jun 4, 2020

    @AspenForester

    Given that I just had a situation where this functionality would have helped me, I would say that this is still relevant in in June 2020

  10. bergmeister commented on Jun 4, 2020

    @bergmeister
    Contributor

    Well it's currently on track for .Net 5, meaning we could get it maybe at the end of this year for PS 7.1 if the API arrives in time (the change in PowerShell should be quite small once the API is there)
    dotnet/runtime#2048

  11. Zian commented on Aug 30, 2021

    @Zian

    Since .Net 5 and PS 7.1 have already shipped while dotnet/runtime#2048 is still "Open" with a milestone of "Future", does that mean this issue is effectively closed with the GitHub equivalent of WONTFIX?

  12. groutoutlook commented on Aug 20, 2025

    @groutoutlook

    behold stale bot.

    EDIT:
    Please consider to support it. My use case is relatively simple, generate a temp file with generated content in stdin (html files) and open in with msedge. Edge can't take html stdin input so I reside to making a temp file, but it couldnt read tmp file there. So I need to create a proper file and delete them instead, which is unnecessary verbose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifIssue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesWaiting - DotNetCorewaiting on a fix/change in .NET

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions