powershell 6,7的新特性。
1每个特性都注明了版本号,从这个版本开始,才支持这个特性。
2欢迎挑毛病,让我更完善帖子。
3大都是ps6的新特性。ps7刚刚开始开发,新特性也只有一点点。
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
}
#所以你要在一个脚本中,分别写2段代码。
if ($IsWindows)
{
copy-item c:\xxx d:\yyy
}
if ($IsLinux)
{
copy-item /home/user1 /home/user2
}
{
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██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
{
#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服务器。
用于linux客户机,连接linux服务器。
命令:
$连接2 = New-PSSession -HostName 127.0.0.1 -UserName user006 #手动输入密码或用-KeyFilePath 选项
Invoke-Command -Session $连接2 -ScriptBlock {new-item ~/ccc.txt}
$连接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
用了-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██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
新增语法糖:
'a'..'z'
'z'..'a'
'c'..'g'
'a'..'z'
'z'..'a'
'c'..'g'
'A'..'Z'
支持中文,但若想使用,必须让区位码相连的,有意义的字符才有用。
例子:
[char]27721 #返回 汉
[char]27726 #返回 汎
'汉'..'汎' #则返回【汉】的区位码,到【汎】区位码之间的字符。汉,汊,汋,汌,汍,汎。好像这样没啥用。
[char]27726 #返回 汎
'汉'..'汎' #则返回【汉】的区位码,到【汎】区位码之间的字符。汉,汊,汋,汌,汍,汎。好像这样没啥用。
'㈠'..'㈩' #返回㈠,㈡,。。㈩,这样就有用了。
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃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屏幕颜色代码。
已经支持linux屏幕颜色代码。
"`e[38;2;128;0;128;48;2;0;0;0m"
https://docs.microsoft.com/zh-cn/windows/console/console-virtual-terminal-sequences
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"
$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
$a = "`u{1f00e}" # 麻将8万。
$a
${`u{1f00e}} = 'a' # 麻将8万。
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.1██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
新增Markdown模块
Invoke-RestMethod https://raw.githubusercontent.com/kubernetes/kubernetes/master/README.md -outfile /tmp/r.md
$a = ConvertFrom-Markdown -LiteralPath /tmp/r.md #把r.md源码渲染成html。
$a.html
$b = ConvertFrom-Markdown -LiteralPath /tmp/r.md -AsVT100EncodedString #把r.md源码渲染成 字符界面+彩色 。
$b.AsVT100EncodedString
ps传教士 原创整理
Get-MarkdownOption
Set-MarkdownOption
查看-设置颜色
Show-Markdown 基本没用
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.1██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
添加ThreadJob模块,中有一个命令:
Start-ThreadJob
SYNTAX
Start-ThreadJob [-ScriptBlock] [-Name ] [-InitializationScript ] [-InputObject ] [-ArgumentList
Start-ThreadJob
SYNTAX
Start-ThreadJob [-ScriptBlock]
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.1██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.1██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
Invoke-RestMethod,Invoke-WebRequest
添加了重试的功能
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.1██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.1██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
PSCustomobject
添加ForEach和Where方法
添加Count和Length属性
添加ForEach和Where方法
添加Count和Length属性
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.1██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
-replace 支持代码块
原来:
"字符串" -replace "查找", {字符串}
"字符串" -replace "查找", {字符串}
现在:
"字符串" -replace "查找", {return "a" * 7} #加入非字符串,则被视为代码块。
"字符串" -replace "查找", {return "a" * 7} #加入非字符串,则被视为代码块。
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.1██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
Select-Object 新增 -SkipIndex 参数
1..8 | Select-Object -SkipIndex 0,2,3
1,2,3,4,5,6,7,8中,去掉第134个,返回2 5 6 7 8
也就是说,【大数组】中,跳过所有【小数组中包含】的元素。
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.2██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
从6.2 preview3开始:
PS /root> 1..3 | Join-String -OutputPrefix "A " -OutputSuffix " B" -Separator "," -SingleQuote
A '1','2','3' B
# 数组插入,分隔符,引号,头尾。
A '1','2','3' B
# 数组插入,分隔符,引号,头尾。
Join-String # 数组 |Join-String
-Property
-Separator 'x' #分隔符x
-OutputPrefix] #最前面加 字符串
[-OutputSuffix #后加
-SingleQuote
#powershell传教士 整理 分享
-DoubleQuote
-FormatString
-Property
-Separator 'x' #分隔符x
-OutputPrefix
[-OutputSuffix
-SingleQuote
#powershell传教士 整理 分享
-DoubleQuote
-FormatString
123 | Join-String -FormatString '{0:N2}'
123.00
123.00
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
以Sort-Object,添加参数-Top,-Bottom,对顶部/底部筛选。
并在6.2 pr4中添加-stable参数
并在6.2 pr4中添加-stable参数
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.2 pr4████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.2 pr4████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
enum枚举新增,支持从类中继承
enum MyEnum : Int64 {
a = [int64]::MaxValue
}
enum MyEnum : Int64 {
a = [int64]::MaxValue
}
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.2 pr4████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
format-hex原来只支持字符串,数组。
现新增支持枚举。
[System.Net.HttpStatusCode]::OK | format-hex
现新增支持枚举。
[System.Net.HttpStatusCode]::OK | format-hex
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.2██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
======
从ps 5.0开始:
模块名:Microsoft.PowerShell.Core
Enter-PSHostProcess 和 Exit-PSHostProcess 让您调试另一个powershell进程。
运行 Enter-PSHostProcess 附加到一个特定的进程 ID,然后再运行得到运行空间返回运行在进程内的活动空间。
运行 Exit-PSHostProcess,当您完成调试进程内的脚本从进程中分离。
从ps 5.0开始:
模块名:Microsoft.PowerShell.Core
Enter-PSHostProcess 和 Exit-PSHostProcess 让您调试另一个powershell进程。
运行 Enter-PSHostProcess 附加到一个特定的进程 ID,然后再运行得到运行空间返回运行在进程内的活动空间。
运行 Exit-PSHostProcess,当您完成调试进程内的脚本从进程中分离。
======
从ps6.2 rc1开始:
Enter-PSHostProcess 新增-CustomPipeName参数,这样就【不需要总变化的进程id】了。
从ps6.2 rc1开始:
Enter-PSHostProcess 新增-CustomPipeName参数,这样就【不需要总变化的进程id】了。
powershell进程1:
pwsh -custompipename mypipe
pwsh -custompipename mypipe
powershell进程2:
Enter-PSHostProcess -CustomPipeName mypipe
Enter-PSHostProcess -CustomPipeName mypipe
2019-04-05 PowerShell v6.2正式版将发布!
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.2██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
Enable-ExperimentalFeature -Name PSTempDrive
后,将增加【temp:】盘符
后,将增加【temp:】盘符
Enable-ExperimentalFeature -Name PSUseAbbreviationExpansion
后,将增加长命令的驼峰缩写
i-arsavsf等于Import-AzRecoveryServicesAsrVaultSettingsFile
后,将增加长命令的驼峰缩写
i-arsavsf等于Import-AzRecoveryServicesAsrVaultSettingsFile
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V7.0pr1 ████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
将QuoteFields参数添加到ConvertTo-Csv和Export-Csv。这允许显式指向要在输出中引用的字段。
将新参数添加-UseQuotes到Export-Csv和ConvertTo-Csv cmdlet:
Never - 不要引用任何东西。
Always - 引用所有内容(当前和默认行为)。
AsNeeded - 仅引用需要它的字段(它们包含分隔符)。
Never - 不要引用任何东西。
Always - 引用所有内容(当前和默认行为)。
AsNeeded - 仅引用需要它的字段(它们包含分隔符)。
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V7.0pr1 ████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
在脚本中,管道符可以放在行首,原来只能在行尾。
原来:
xxx1 |
xxx2 |
xxx3
xxx1 |
xxx2 |
xxx3
现在:
xxx1
| xxx2
| xxx3
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V7.0pr1 ████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
powershell 新增线程方法重载?
$r1 = [powershell]::Create().AddScript('1..10 | % { [console]::WriteLine("#1 running $_"); sleep 1 }').InvokeAsync()
$r2 = [powershell]::Create().AddScript('1..15 | % { [console]::WriteLine("#2 running $_"); sleep 1 }').InvokeAsync()
$r3 = [powershell]::Create().AddScript('1..13 | % { [console]::WriteLine("#3 running $_"); sleep 1 }').beginInvoke()
$r2 = [powershell]::Create().AddScript('1..15 | % { [console]::WriteLine("#2 running $_"); sleep 1 }').InvokeAsync()
$r3 = [powershell]::Create().AddScript('1..13 | % { [console]::WriteLine("#3 running $_"); sleep 1 }').beginInvoke()
[system.threading.tasks.task]::waitall($r1, $r2, $r3); write-host "All tasks done"
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V7.0pr2 ████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
-split 支持负数
PS /root> 'a b c d' -split ' ',-2
a b c
d
a b c
d
PS /root> 'a b c d' -split ' ',-3
a b
c
d
a b
c
d
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview3 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview3 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
新增并发参数
| ForEach-Object -Parallel
| ForEach-Object -Parallel
太爽了 :
get-content ip.txt |foreach-object -Parallel{ ping.exe $_ }
get-content ip.txt |foreach-object -Parallel{ ping.exe $_ }
Get-Content /powershell/ip.txt |ForEach-Object -Parallel {if (Test-Connection -Count 1 -TargetName $_ -Quiet) {$_} } 6>$null
手册:
https://github.com/PowerShell/PowerShell-RFC/blob/master/4-Experimental-Accepted/RFC0044-ForEach-Parallel-Cmdlet.md
https://github.com/PowerShell/PowerShell-RFC/blob/master/4-Experimental-Accepted/RFC0044-ForEach-Parallel-Cmdlet.md
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview3 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview3 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
Select-String -raw
默认会输出行号,
加上这个参数,只输出匹配。
加上这个参数,只输出匹配。
----------------------------------------------------------------
还有些细小的特性,我可能忘记添加在这里,欢迎提醒我补充,谢谢观看。
此贴不定期更新,更新新特性。