Skip to content

Commit

Permalink
tip: Update tip info and wording a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlydog committed Oct 2, 2023
1 parent aab0c84 commit b35bd00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
$tip = [tiPS.PowerShellTip]::new()
$tip.CreatedDate = [DateTime]::Parse('2023-10-02')
$tip.Title = 'Quickly create temporary file in PowerShell'
$tip.Title = 'Quickly create temporary file'
$tip.TipText = @'
Quickly create a temporary file using dotnet class.
Quickly create a temporary file by using the New-TemporaryFile command, or the GetTempFileName() .NET function.
This is handy when you want save data to a temporary log file and not worry about path/permissions/filename.
Temporary file will be created in "C:\Users\USER\AppData\Local\Temp\1\some-tmp.tmp" and automatically cleaned up after reboot.
This is handy when you want save data to a temporary log file and not worry about path/permissions/filename. The temporary file will be created in "C:\Users\USER\AppData\Local\Temp\1\some-tmp.tmp".
'@
$tip.Example = @'
$tmpFile = [System.IO.Path]::GetTempFileName()
# Using native PowerShell cmdlet
$tmpFile = New-TemporaryFile
# Easily write/read/remove
# Create temp file and get the path to it using the .NET class.
[string] $tmpFile = [System.IO.Path]::GetTempFileName()
# Or use the native PowerShell cmdlet instead, which returns a full FileInfo object.
[System.IO.FileInfo] $tmpFile = New-TemporaryFile
# Easily write/read/remove the temp file.
"Some data to be saved" | Out-File $tmpFile
# Cleanup when you no longer need it
# Cleanup when you no longer need it.
Remove-Item $tmpFile
'@
$tip.Urls = @(
'https://learn.microsoft.com/en-us/dotnet/api/system.io.path.gettempfilename?view=net-7.0#system-io-path-gettempfilename'
'https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/new-temporaryfile'
'https://learn.microsoft.com/en-us/dotnet/api/system.io.path.gettempfilename#system-io-path-gettempfilename'
)
$tip.Category = [tiPS.TipCategory]::Syntax # Community, Editor, Module, NativeCmdlet, Performance, Syntax, Terminal, or Other.

Expand Down
11 changes: 11 additions & 0 deletions src/tiPS/PowerShellTips.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,16 @@
"https://www.linkedin.com/feed/update/urn:li:activity:7113300637735407618/"
],
"Category": 5
},
{
"CreatedDate": "2023-10-02T00:00:00",
"Title": "Quickly create temporary file",
"TipText": "Quickly create a temporary file by using the New-TemporaryFile command, or the GetTempFileName() .NET function.\r\n\r\nThis is handy when you want save data to a temporary log file and not worry about path/permissions/filename. The temporary file will be created in \"C:\\Users\\USER\\AppData\\Local\\Temp\\1\\some-tmp.tmp\".",
"Example": "# Create temp file and get the path to it using the .NET class.\r\n[string] $tmpFile = [System.IO.Path]::GetTempFileName()\r\n\r\n# Or use the native PowerShell cmdlet instead, which returns a full FileInfo object.\r\n[System.IO.FileInfo] $tmpFile = New-TemporaryFile\r\n\r\n# Easily write/read/remove the temp file.\r\n\"Some data to be saved\" | Out-File $tmpFile\r\n\r\n# Cleanup when you no longer need it.\r\nRemove-Item $tmpFile",
"Urls": [
"https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/new-temporaryfile",
"https://learn.microsoft.com/en-us/dotnet/api/system.io.path.gettempfilename#system-io-path-gettempfilename"
],
"Category": 5
}
]

0 comments on commit b35bd00

Please sign in to comment.