Tag: Tempfile

PowerShell New-TemporaryFile

Create a tempfile with PowerShell

When I was using PowerShell in the early stages it was limited in some features, now with PowerShell version 5 Microsoft added some great new features to it. This time it’s about creating a tempfile. I already wrote a blog post in 2011 how you can create a tempfile in older version of PowerShell using .NET:

$tempFile = [System.IO.Path]::GetTempFileName()

With PowerShell 5 you got a native cmdlet for this:

$tempFile = New-TemporaryFile

Powershell: Create a tempfile with Powershell

Powershell Header

Sometimes you need to save some data in to a tempfile. And instead of creating a ownen file for this you could use the .NET function to create a really tempfile in the tempfile directory.

This is the how you can create a new tempfile:

$tempFile = [System.IO.Path]::GetTempFileName()

And now you can parse data into this file.