question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:16
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
mklement0commented, Jul 11, 2017

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.

2reactions
bergmeistercommented, Jun 4, 2020

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) https://github.com/dotnet/runtime/issues/2048

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How can I create a temp file with a specific extension ...
string tempDirectory = @"c:\\temp"; TempFileCollection coll = new TempFileCollection(tempDirectory, true); string filename = coll.AddExtension(" ...
Read more >
Temporary file with given extension.
Creating temporary file in PowerShell is pretty simple – because you can use .NET call directly it's a matter of: [IO.
Read more >
Create Temporary Files with PowerShell 5 - Scripting Blog
Summary: Ed Wilson, Microsoft Scripting Guy, talks about creating temporary files with Windows PowerShell 5.0 in Windows 10.
Read more >
tempfile — Generate temporary files and directories
This module creates temporary files and directories. It works on all supported platforms. TemporaryFile , NamedTemporaryFile , TemporaryDirectory , and ...
Read more >
Create temporary files and directories using Python-tempfile
We can create a temporary file in a secure manner using mkstemp(). The file created by this method is readable and writable only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found