Add ability to create a temporary file with a specific extension to New-TemporaryFile
See original GitHub issueRelated: #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:
- Created 6 years ago
- Reactions:16
- Comments:15 (11 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.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