PowerTip: Use PowerShell to Create Temporary File Name

Summary: Use Windows PowerShell to create a temporary file name.

Hey, Scripting Guy! Question I need to output data to a file, but I do not need a permanent file name and location because
           the file will be later deleted. How can I easily use Windows PowerShell to create a temporary file name?

Hey, Scripting Guy! Answer Use the GetTempFileName static method from the System.IO.Path .NET Framework class:


Comments (4)

  1. narkotsky says:

    Be aware, though, simply getting the filename also creates a placeholder!

  2. It requires to run as Admin, otherwise it returns empty string

    1. This DOESN’T require admin privileges as the file is created in the local temp folder of the user.

      But simply using the function does create a 0 byte file of the same name.

Skip to main content