In PowerShell the standard way to create a temporary filename is to invoke the System.IO namespace's Path class's GetTempFileName method. To be clear, only a filename is retrieved and no actual file is created. An example of GetTempFileName being invoked by PowerShell is as follows:
The results of the code above will vary because the filename is randomly generated and the method uses a user's environment variable, $env:TEMP. An example of the value assigned to $tempFilenameFromCsharp when the code snippet above being invoked is as follows:
C:\Users\jann\AppData\Local\Temp\tmpCF88.tmp
For those that need a reminder, the WhatIf command-line option is defined as follows (see: WhatIf Switch):
My attempt to use New-TemporaryFile to create filename without creating a file was as follows:
The output from invoking the above command is follows:
Not every idea we try works.
No comments :
Post a Comment