May PowerShell Oneliner
In case you missed this recent SAPIEN newsletter, here’s my one liner for this month.
I have a quick one-liner that will create a random filename with a preferred file extension in a folder that you specify. By default the GetRandomFileName() method will return a short 8.3 string with a random file name and extension. My one-liner uses the ChangeExtension() method to change the extension to something you prefer and the Join-Path cmdlet to combine a folder path with the random file name.
PS C:\> $myfile=[system.io.path]::changeExtension((join-path “c:\files” ([system.io.path]::GetRandomFileName())),”log”)
PS C:\> $myfile
c:\files\gknnawtt.log
PS C:\>
Now you have a temporary file to use with an extension you prefer in a location that you specify.
Tags: Extension, File, IO, powershell, scripting