我原創整理的powershell 6,7的新特性。基本可以說網上唯一。 1每個特性都註明瞭版本號,從這個版本開始,才支持這個特性。 2歡迎挑毛病,讓我更完善帖子。 3大都是ps6的新特性。ps7剛剛開始開發,新特性也只有一點點。 ...
powershell 6,7的新特性。
1每個特性都註明瞭版本號,從這個版本開始,才支持這個特性。
2歡迎挑毛病,讓我更完善帖子。
3大都是ps6的新特性。ps7剛剛開始開發,新特性也只有一點點。
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
在 powershell 6.0 中新增內置變數
$IsCoreCLR
$IsLinux
$IsMacOS
$IsWindows
用於判斷系統。 #假想中的複製文件腳本,由於win,linux目錄路徑,不相容。
#所以你要在一個腳本中,分別寫2段代碼。
if ($IsWindows)
{
copy-item c:\xxx d:\yyy
} if ($IsLinux)
{
copy-item /home/user1 /home/user2
}
powershell 傳教士 分享!2016-12-02
if ($PSEdition -eq 'Desktop') #ps v5.1支持
{
#win
} if ($PSEdition -eq 'Core')
{
#ps6 in win,ps6 in linux
}
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛ powershell6.0即linux版中,New-PSSession新增3個參數, 【-HostName】, 【-UserName】, 【-KeyFilePath】, -SSHTransport 布爾型 強制使用ssh協議,而不是winrm協議
用於linux客戶機,連接linux伺服器。 命令:
$連接2 = New-PSSession -HostName 127.0.0.1 -UserName user006 #手動輸入密碼或用-KeyFilePath 選項
Invoke-Command -Session $連接2 -ScriptBlock {new-item ~/ccc.txt} 用了-HostName參數後,埠預設22。
用了-computername參數後,埠預設5985。
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
Get-Content $Path -Encoding Byte
變更為
Get-Content $Path -AsByteStream ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛ 新增語法糖:
'a'..'z'
'z'..'a'
'c'..'g'
'A'..'Z'
支持中文,但若想使用,必須讓區位碼相連的,有意義的字元才有用。 例子: [char]27721 #返回 漢
[char]27726 #返回 汎
'漢'..'汎' #則返回【漢】的區位碼,到【汎】區位碼之間的字元。漢,汊,汋,汌,汍,汎。好像這樣沒啥用。
'㈠'..'㈩' #返回㈠,㈡,。。㈩,這樣就有用了。
---------------------------------------------------------------- ┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
import-csv 現在已經支持
`r,`n,`r`n 格式的回車。
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛ powershell 6.0:
已經支持linux屏幕顏色代碼。 "`e[38;2;128;0;128;48;2;0;0;0m"
https://docs.microsoft.com/zh-cn/windows/console/console-virtual-terminal-sequences $green="`e[92m"
$none="`e[0m"
$red="`e[91m"
$yellow="`e[93m"
$magenta="`e[95m"
$cyan="`e[96m" echo "$green powershell 支持linux顏色 $none 例子"
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
linux中支持。win中不支持。
特殊符號
"`u{1f44d}" # evals to