header image

WMF 5.0–New-TemporaryFile

Posted by: | April 30, 2015 Comments Off on WMF 5.0–New-TemporaryFile |

Creating a temporary file in PowerShell 4.0 and earlier has been possible using a number of techniques such as:

£> $file = [System.IO.Path]::GetTempFileName()
£> $file


With the April 2015 WMF 5.0 preview this becomes much easier

£> $file2 = New-TemporaryFile
£> $file2

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

Mode                LastWriteTime         Length Name
—-                ————-         —— —-
-a—-        4/30/2015  12:42 PM              0 tmp1FE1.tmp


Now you can create files simply and easily without having to remember the .NET syntax.


Notice that the temporary files are automatically created in your TEMP folder.

£> $env:TEMP

under: PowerShell v5

Comments are closed.