diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewTemporaryFileCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewTemporaryFileCommand.cs
new file mode 100644
index 0000000000..2ea9133903
--- /dev/null
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewTemporaryFileCommand.cs
@@ -0,0 +1,46 @@
+
+using System;
+using System.IO;
+using System.Management.Automation;
+
+namespace Microsoft.PowerShell.Commands
+{
+ ///
+ /// The implementation of the "New-TemporaryFile" cmdlet
+ ///
+ [Cmdlet(VerbsCommon.New, "TemporaryFile", SupportsShouldProcess = true, HelpUri = "https://go.microsoft.com/fwlink/?LinkId=526726")]
+ [OutputType(typeof(System.IO.FileInfo))]
+ public class NewTemporaryFileCommand : Cmdlet
+ {
+ ///
+ /// returns a TemporaryFile
+ ///
+ protected override void EndProcessing()
+ {
+ string filePath = null;
+ string tempPath = System.Environment.GetEnvironmentVariable("TEMP");
+ if (ShouldProcess(tempPath))
+ {
+ try
+ {
+ filePath = Path.GetTempFileName();
+ }
+ catch (Exception e)
+ {
+ WriteError(
+ new ErrorRecord(
+ e,
+ "NewTemporaryFileWriteError",
+ ErrorCategory.WriteError,
+ tempPath));
+ return;
+ }
+ if (!string.IsNullOrEmpty(filePath))
+ {
+ FileInfo file = new FileInfo(filePath);
+ WriteObject(file);
+ }
+ }
+ }
+ }
+}
diff --git a/src/Modules/Shared/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psm1 b/src/Modules/Shared/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psm1
index 7ab842bd1d..731053a230 100644
--- a/src/Modules/Shared/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psm1
+++ b/src/Modules/Shared/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psm1
@@ -141,37 +141,6 @@ function Get-FileHash
}
}
-<# This cmdlet is used to create a new temporary file in $env:temp #>
-function New-TemporaryFile
-{
- [CmdletBinding(
- HelpURI='https://go.microsoft.com/fwlink/?LinkId=526726',
- SupportsShouldProcess=$true)]
- [OutputType([System.IO.FileInfo])]
- Param()
-
- Begin
- {
- try
- {
- if($PSCmdlet.ShouldProcess($env:TEMP))
- {
- $tempFilePath = [System.IO.Path]::GetTempFileName()
- }
- }
- catch
- {
- $errorRecord = [System.Management.Automation.ErrorRecord]::new($_.Exception,"NewTemporaryFileWriteError", "WriteError", $env:TEMP)
- Write-Error -ErrorRecord $errorRecord
- return
- }
-
- if($tempFilePath)
- {
- Get-Item $tempFilePath
- }
- }
-}
<############################################################################################
# Format-Hex cmdlet helps in displaying the Hexadecimal equivalent of the input data.
############################################################################################>
diff --git a/src/Modules/Unix/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 b/src/Modules/Unix/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1
index 6fd68da654..00192551dd 100644
--- a/src/Modules/Unix/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1
+++ b/src/Modules/Unix/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1
@@ -22,8 +22,8 @@ CmdletsToExport= "Format-List", "Format-Custom", "Format-Table", "Format-Wide",
"Get-PSBreakpoint", "Remove-PSBreakpoint", "Enable-PSBreakpoint", "Disable-PSBreakpoint", "Get-PSCallStack",
"Get-TraceSource", "Set-TraceSource", "Trace-Command",
"Get-Runspace", "Debug-Runspace", "Enable-RunspaceDebug", "Disable-RunspaceDebug",
- "Get-RunspaceDebug", "Wait-Debugger" , "Get-Uptime"
-FunctionsToExport= "Get-FileHash", "New-TemporaryFile", "Format-Hex", "Import-PowerShellDataFile"
+ "Get-RunspaceDebug", "Wait-Debugger" , "Get-Uptime", "New-TemporaryFile"
+FunctionsToExport= "Get-FileHash", "Format-Hex", "Import-PowerShellDataFile"
AliasesToExport= "fhx"
NestedModules="Microsoft.PowerShell.Commands.Utility.dll","Microsoft.PowerShell.Utility.psm1"
HelpInfoURI = 'https://go.microsoft.com/fwlink/?linkid=390787'
diff --git a/src/Modules/Windows-Core/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 b/src/Modules/Windows-Core/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1
index 57643dae87..4959588d9d 100644
--- a/src/Modules/Windows-Core/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1
+++ b/src/Modules/Windows-Core/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1
@@ -19,12 +19,11 @@ CmdletsToExport= "Format-List", "Format-Custom", "Format-Table", "Format-Wide",
"Group-Object", "Sort-Object", "Get-Variable", "New-Variable", "Set-Variable", "Remove-Variable",
"Clear-Variable", "Export-Clixml", "Import-Clixml", "ConvertTo-Xml", "Select-Xml", "Write-Debug",
"Write-Verbose", "Write-Warning", "Write-Error", "Write-Information", "Write-Output", "Set-PSBreakpoint",
- "Get-PSBreakpoint", "Remove-PSBreakpoint", "Enable-PSBreakpoint", "Disable-PSBreakpoint", "Get-PSCallStack",
+ "Get-PSBreakpoint", "Remove-PSBreakpoint", "New-TemporaryFile", "Enable-PSBreakpoint", "Disable-PSBreakpoint", "Get-PSCallStack",
"Get-TraceSource", "Set-TraceSource", "Trace-Command",
"Unblock-File", "Get-Runspace", "Debug-Runspace", "Enable-RunspaceDebug", "Disable-RunspaceDebug",
"Get-RunspaceDebug", "Wait-Debugger" , "Get-Uptime"
-FunctionsToExport= "Get-FileHash", "New-TemporaryFile", "Format-Hex", "Import-PowerShellDataFile",
- "ConvertFrom-SddlString"
+FunctionsToExport= "Get-FileHash", "Format-Hex", "Import-PowerShellDataFile", "ConvertFrom-SddlString"
AliasesToExport= "fhx"
NestedModules="Microsoft.PowerShell.Commands.Utility.dll","Microsoft.PowerShell.Utility.psm1"
HelpInfoURI = 'https://go.microsoft.com/fwlink/?linkid=390787'
diff --git a/src/Modules/Windows-Full/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 b/src/Modules/Windows-Full/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1
index b7b5892c60..5179fdcda3 100644
--- a/src/Modules/Windows-Full/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1
+++ b/src/Modules/Windows-Full/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1
@@ -24,9 +24,8 @@ CmdletsToExport= "Format-List", "Format-Custom", "Format-Table", "Format-Wide",
"Remove-PSBreakpoint", "Enable-PSBreakpoint", "Disable-PSBreakpoint", "Get-PSCallStack",
"Send-MailMessage", "Get-TraceSource", "Set-TraceSource", "Trace-Command", "Show-Command", "Unblock-File",
"Get-Runspace", "Debug-Runspace", "Enable-RunspaceDebug", "Disable-RunspaceDebug", "Get-RunspaceDebug", "Wait-Debugger",
- "ConvertFrom-String", "Convert-String" , "Get-Uptime"
-FunctionsToExport= "Get-FileHash", "New-TemporaryFile", "Format-Hex", "Import-PowerShellDataFile",
- "ConvertFrom-SddlString"
+ "ConvertFrom-String", "Convert-String" , "Get-Uptime", "New-TemporaryFile"
+FunctionsToExport= "Get-FileHash", "Format-Hex", "Import-PowerShellDataFile", "ConvertFrom-SddlString"
AliasesToExport= "CFS", "fhx"
NestedModules="Microsoft.PowerShell.Commands.Utility.dll","Microsoft.PowerShell.Utility.psm1"
HelpInfoURI = 'https://go.microsoft.com/fwlink/?linkid=390787'
diff --git a/src/vs-csproj/Microsoft.PowerShell.Commands.Utility.csproj b/src/vs-csproj/Microsoft.PowerShell.Commands.Utility.csproj
index dd533298e7..3ab886baeb 100644
--- a/src/vs-csproj/Microsoft.PowerShell.Commands.Utility.csproj
+++ b/src/vs-csproj/Microsoft.PowerShell.Commands.Utility.csproj
@@ -229,6 +229,9 @@
commands\utility\NewGuidCommand.cs
+
+ commands\utility\NewTemporaryFileCommand.cs
+
commands\utility\NewTimeSpanCommand.cs