PowerShell 動詞 (PowerShell Approved Verbs) | 繁體中文譯 (Meaning in Traditional Chinese) |
---|---|
Add | 加入 |
Clear | 清除 |
Close | 關閉 |
Copy | 複製 |
Enter | 輸入 |
Exit | 退出 |
Find | 尋找 |
Format | 格式 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fibonacci - Interation | |
Function FibI { | |
[CmdletBinding()] | |
[Parameter(Position = 0)] | |
param ([int]$index) | |
Set-StrictMode -Version Latest | |
if ($index -eq 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fibonacci - Recursion | |
Function FibR { | |
[CmdletBinding()] | |
[Parameter(Position = 0)] | |
param ([int]$index) | |
Set-StrictMode -Version Latest | |
if ($index -lt 2) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is iteration | |
9:42 PM> Measure-Command -Expression {FibI 20} | |
... | |
TotalSeconds : 0.0093811 | |
TotalMilliseconds : 9.3811 | |
# This is recursion | |
9:43 PM> Measure-Command -Expression {FibR 20} | |
... | |
TotalSeconds : 22.7287975 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Invoke-BetterWebRequest { | |
[CmdletBinding()] | |
param( | |
# Hashtable for the Invoke-WebRequest | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)] | |
[hashtable] | |
$iwrSplat | |
) | |
try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$InterfaceAlias = 'Wi-Fi' | |
while ((Get-NetIPAddress -InterfaceAlias $InterfaceAlias -AddressFamily IPv4).IPAddress -like '169*') | |
{ | |
$arg = '/C ipconfig /renew' | |
Start-Process -FilePath 'cmd.exe' -argumentlist $arg -wait -PassThru | |
Start-Sleep -Seconds 3 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-LifeCalendar { | |
[CmdletBinding()] | |
Param( | |
$StartDate = (Get-Date -Date '1980-01-01'), | |
$LifeinYear = 75 | |
) | |
# A powershell function to display the life calendar in weeks. | |
# Original idea from: https://waitbutwhy.com/2014/05/life-weeks.html | |
$DaysSinceStartDate = (New-TimeSpan -Start $StartDate -End (Get-Date)).Days |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code snippets to tranlate PowerShell approved verbs into different language using AWS Translate | |
# This snippet assumes the AWS credential and AWS default regions have been set. | |
# Also, make sure your console environment supports the target encoding. | |
$Verb = (Get-Verb).Verb | |
# Find Language code here: | |
# https://docs.aws.amazon.com/powershell/latest/reference/items/ConvertTo-TRNTargetLanguage.html | |
$SourceLanguageCode = 'en' | |
$TargetLanguageCode = 'zh-TW' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GeneratePesterTest | |
{ | |
# Generate Pester tests from PSCustomObject's NoteProperty | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory = $true)] | |
[PSCustomObject]$InputObject, | |
#The object name that you are comparing with in your test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ConvertTo-SSMDocument | |
{ | |
<# | |
.Synopsis | |
Convert a script into SSM Command document | |
.DESCRIPTION | |
This cmdlet convert a script into SSM Command document. | |
.EXAMPLE | |
PS:\ > ConvertTo-SSMDocument -Expression 'Get-Service' | |
{ |