Add New-TemporaryDirectory cmdlet#27549
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds the new New-TemporaryDirectory cmdlet to PowerShell Utility, wires it into module exports/default command verification, and introduces Pester coverage + documentation status update.
Changes:
- Adds
New-TemporaryDirectorycmdlet implementation (NewTemporaryDirectoryCommand.cs). - Exports the cmdlet from
Microsoft.PowerShell.Utility(Windows/Unix manifests) and registers it in default-command verification. - Adds Pester tests for the cmdlet and updates the cmdlet test-status documentation table.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/powershell/engine/Basic/DefaultCommands.Tests.ps1 | Adds New-TemporaryDirectory to the default cmdlet/alias verification matrix. |
| test/powershell/Modules/Microsoft.PowerShell.Utility/New-TemporaryDirectory.Tests.ps1 | Introduces Pester coverage for creation/uniqueness/WhatIf/output type. |
| src/Modules/Windows/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 | Exports New-TemporaryDirectory on Windows. |
| src/Modules/Unix/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 | Exports New-TemporaryDirectory on Unix. |
| src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewTemporaryDirectoryCommand.cs | Implements the cmdlet with SupportsShouldProcess and error handling. |
| docs/testing-guidelines/PowerShellCoreTestStatus.md | Marks New-TemporaryDirectory as delivered/tested in the status table. |
| It "has an OutputType of System.IO.DirectoryInfo" { | ||
| (Get-Command New-TemporaryDirectory).OutputType | Should -BeExactly "System.IO.DirectoryInfo" | ||
| } |
There was a problem hiding this comment.
Addressed in 2777e98c0: the test now checks (Get-Command New-TemporaryDirectory).OutputType.Name with Should -Contain "System.IO.DirectoryInfo", so it handles the output type collection correctly.
| string tempPath = Path.GetTempPath(); | ||
| if (ShouldProcess(tempPath)) |
There was a problem hiding this comment.
Addressed in 2777e98c0: the cmdlet now generates the candidate temp directory path before ShouldProcess and uses that full path as the target. The focused Pester run also shows the -WhatIf message now points at the generated tmp_* directory path.
| catch (IOException ioException) | ||
| { | ||
| ThrowTerminatingError( | ||
| new ErrorRecord( | ||
| ioException, | ||
| "NewTemporaryDirectoryWriteError", | ||
| ErrorCategory.WriteError, | ||
| tempPath)); | ||
| } |
There was a problem hiding this comment.
Addressed in 2777e98c0: directory creation now wraps both IOException and UnauthorizedAccessException in terminating ErrorRecords, using PermissionDenied for access failures and the generated directory path as the target.
PR Summary
Add
New-TemporaryDirectorytoMicrosoft.PowerShell.Utility.The new cmdlet follows the shape of
New-TemporaryFile: it supportsShouldProcess, uses low confirmation impact, exports from the Utility module on Windows and Unix, and returns aSystem.IO.DirectoryInfofor a unique directory under the system temp path.PR Context
Fixes #25754.
The working group recommended adding
New-TemporaryDirectoryso users can create temporary directories without calling[System.IO]directly. That matters in constrained and restricted language modes where direct .NET type access is not available.Validation
git diff --checkSystem.Management.Automation.Language.ParserStart-PSBuild -Clean -PSModuleRestore -UseNuGetOrgStart-PSPester -Path test/powershell/Modules/Microsoft.PowerShell.Utility/New-TemporaryDirectory.Tests.ps1 -Tag CI -SkipTestToolBuild -UseNuGetOrg(4 passed)Start-PSPester -Path test/powershell/engine/Basic/DefaultCommands.Tests.ps1 -Tag CI -UseNuGetOrg(290 passed)New-TemporaryDirectoryreturnsSystem.IO.DirectoryInfo, creates the directory, and places it under[System.IO.Path]::GetTempPath()PR Checklist
masterbranch.