Dangerous Temp Files!

by Mar 10, 2017

Internal system functions are often helpful, but always make sure you fully understand what they do.

A particularly popular system method is called GetTempFileName() and produces temporary file names. When you look a bit closer, though, you’ll notice that it not just produces temporary file names, but also temporary files:

$file = [System.IO.Path]::GetTempFileName()
Test-Path -Path $file

So you’ll end up with tons of orphaned files if you use this method in your scripts simply to create temporary file names.

Twitter This Tip! ReTweet this Tip!