Skip to content

Commit 8103c80

Browse files
committed
tip: Tip for ExpandEnvironmentVariables
1 parent c729610 commit 8103c80

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
$tip = [tiPS.PowerShellTip]::new()
2+
$tip.CreatedDate = [DateTime]::Parse('2024-07-18')
3+
$tip.Title = 'Easily expand environment variables in a string'
4+
$tip.TipText = @'
5+
You can use the `[System.Environment]::ExpandEnvironmentVariables()` method to easily expand environment variables in a string. Simply wrap the environment variable name in % characters. You can even expand multiple environment variables in a single string.
6+
'@
7+
$tip.Example = @'
8+
# Expand a single environment variable and store it in a variable.
9+
$tempDirectoryPath = [System.Environment]::ExpandEnvironmentVariables('%TEMP%')
10+
11+
# Alternative is to use the $Env: syntax to retrieve a single environment variable.
12+
$tempDirectoryPath = $Env:TEMP
13+
14+
# Expand multiple environment variables in a string.
15+
[System.Environment]::ExpandEnvironmentVariables('My system drive is %SystemDrive% and my system root is %SystemRoot%')
16+
'@
17+
$tip.Urls = @(
18+
'https://learn.microsoft.com/en-us/dotnet/api/system.environment.expandenvironmentvariables'
19+
'https://x.com/adbertram/status/1777421663581130856'
20+
)
21+
$tip.Category = [tiPS.TipCategory]::NativeCmdlet # Community, Editor, Module, NativeCmdlet, Performance, Security, Syntax, Terminal, or Other.
22+
$tip.Author = 'Daniel Schroeder (deadlydog)' # Optional. Get credit for your tip. e.g. 'Daniel Schroeder (deadlydog)'.
23+
#$tip.ExpiryDate = [DateTime]::Parse('2024-10-30') # Optional. If the tip is not relevant after a certain date, set the expiration date. e.g. Announcing a conference or event.
24+
25+
# Category meanings:
26+
# Community: Social events and community resources. e.g. PowerShell Summit, podcasts, etc.
27+
# Editor: Editor tips and extensions. e.g. VSCode, ISE, etc.
28+
# Module: Modules and module tips. e.g. PSScriptAnalyzer, Pester, etc.
29+
# NativeCmdlet: Native cmdlet tips. e.g. Get-Process, Get-ChildItem, Get-Content, etc.
30+
# Performance: Tips to improve runtime performance. e.g. foreach vs ForEach-Object, ForEach-Object -Parallel, etc.
31+
# Security: Security tips. e.g. ExecutionPolicy, Constrained Language Mode, passwords, etc.
32+
# Syntax: Syntax tips. e.g. splatting, pipeline, etc.
33+
# Terminal: Terminal shortcuts and tips. e.g. PSReadLine, Windows Terminal, ConEmu, etc.
34+
# Other: Tips that don't fit into any of the other categories.

0 commit comments

Comments
 (0)