Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

using System;
using System.IO;
using System.Management.Automation;

namespace Microsoft.PowerShell.Commands
{
/// <summary>
/// The implementation of the "New-TemporaryFile" cmdlet
/// </summary>
[Cmdlet(VerbsCommon.New, "TemporaryFile", SupportsShouldProcess = true, HelpUri = "https://go.microsoft.com/fwlink/?LinkId=526726")]
[OutputType(typeof(System.IO.FileInfo))]
public class NewTemporaryFileCommand : Cmdlet
{
/// <summary>
/// returns a TemporaryFile
/// </summary>
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);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
############################################################################################>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions src/vs-csproj/Microsoft.PowerShell.Commands.Utility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@
<Compile Include="..\Microsoft.PowerShell.Commands.Utility\commands\utility\NewGuidCommand.cs">
<Link>commands\utility\NewGuidCommand.cs</Link>
</Compile>
<Compile Include="..\Microsoft.PowerShell.Commands.Utility\commands\utility\NewTemporaryFileCommand.cs">
<Link>commands\utility\NewTemporaryFileCommand.cs</Link>
</Compile>
<Compile Include="..\Microsoft.PowerShell.Commands.Utility\commands\utility\NewTimeSpanCommand.cs">
<Link>commands\utility\NewTimeSpanCommand.cs</Link>
</Compile>
Expand Down