In the same vein as Quickly create a large file on a Linux system, I\'d like to quickly create a large file on a Windows system. By large I\'m thinking 5 GB.
Temp files should be stored in the Windows Temp Folder. Based on the answer from Rod you can use the following one liner to create a 5 GB temp file which returns the filename
[System.IO.Path]::GetTempFileName() | % { [System.IO.File]::Create($_).SetLength(5gb).Close;$_ } | ? { $_ }
Explanation:
[System.IO.Path]::GetTempFileName()
generates a random filename with random extension in the Windows Temp Folder[System.IO.File]::Create($_)
which creates the file.SetLength(5gb)
. I was a bit surprised to discover, that PowerShell supports Byte Conversion, which is really helpful..close
to allow other applications to access it;$_
the filename is returned and with | ? { $_ }
it is ensured that only the filename is returned and not the empty string returned by [System.IO.File]::Create($_)