Powershell Tip #36: Create a temporary file

By | September 7, 2015

Tip: You can use a temporary file (ex: script, function, …) and then just clean up (delete) at the end once you don’t need that.

Instead of hardcoding a path for a temporary file, you can use the GetTempFileName method.

In PowerShell v5, there is a new cmdlet : New-TemporaryFile

temporary-file-v5-powershell


previous-buttonnext-button

4 thoughts on “Powershell Tip #36: Create a temporary file

  1. Pingback: Powershell Tip #37: Determine the Forest and Domain functional levels | Powershell Guru

  2. Bob mcCoy

    The method name is a little deceptive. It not only generates a name, it creates the associated (empty) file. So it is incumbent upon you, the scripter, to clean up after yourself.

    Reply
    1. Steve Renard Post author

      True, I agree with you. I often use this method to avoid hardcoding paths but the inconvenient is that the scripter needs to clean up the created file.

      Reply
  3. Pingback: Powershell Tip #35: List and remove a function | Powershell Guru

Leave a Reply

Your email address will not be published. Required fields are marked *