Skip to content

Fix New-PSFTempFile ignoring -FileName - #748

Open
TohruSu wants to merge 1 commit into
PowershellFrameworkCollective:developmentfrom
TohruSu:fix-new-psftempfile-filename
Open

TohruSu wants to merge 1 commit into
PowershellFrameworkCollective:developmentfrom
TohruSu:fix-new-psftempfile-filename

Conversation

@TohruSu

@TohruSu TohruSu commented Nov 22, 2026

Copy link
Copy Markdown

Fixes #747

New-PSFTempFile built the path for -FileName but never assigned it, so that path was written to the output and the command went on with the generated name. With -FileName it returned two paths: the requested one, which was never created, and a generated PSF_Temp_<guid> file, which was the only one created and tracked by Get-PSFTempItem.

The path is now assigned to $newPath, the same way New-PSFTempDirectory handles -DirectoryName. The command returns a single path and creates and tracks that file.

Since the requested name is now actually used, an existing file with that name in the temp folder is emptied by New-Item -Force (unchanged), and Remove-PSFTempItem deletes it later.

Testing (Windows 10):

  • Added tests/functions/temp/New-PSFTempFile.Tests.ps1, with and without -FileName. The -FileName test fails without the fix (2 results instead of 1).
  • tests/pester.ps1 on Windows PowerShell 5.1 with Pester 6.2.0: 6492 tests, no failures. The new tests also pass on PowerShell 7.7 with Pester 5.9.1.
  • PSScriptAnalyzer is not installed here, so those tests did not run locally.

I left changelog.md alone since it is written per release; happy to add an entry if you prefer.

The path built for -FileName was written to the output instead of
being assigned to $newPath, so the command returned two paths and
only created and tracked the generated file.

Fixes PowershellFrameworkCollective#747

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New-PSFTempFile - returns two values if specifying filename

1 participant