powershell6,7新特性


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  ??
$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
    ] [-ThrottleLimit ] []
   
    Start-ThreadJob [-FilePath] [-Name ] [-InitializationScript ] [-InputObject ] [-ArgumentList     ]>] [-ThrottleLimit ] []   ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃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██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛   PSCustomobject
添加ForEach和Where方法
添加Count和Length属性      
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.1██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
-replace  支持代码块 原来:
"字符串" -replace "查找", {字符串} 现在:
"字符串" -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
# 数组插入,分隔符,引号,头尾。 Join-String  # 数组 |Join-String
-Property
-Separator 'x' #分隔符x
-OutputPrefix ]  #最前面加 字符串
[-OutputSuffix   #后加
-SingleQuote
#powershell传教士 整理 分享
-DoubleQuote
-FormatString 123 | Join-String -FormatString '{0:N2}'
123.00
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛   以Sort-Object,添加参数-Top,-Bottom,对顶部/底部筛选。
并在6.2 pr4中添加-stable参数   ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.2 pr4████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛ enum枚举新增,支持从类中继承
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
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃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,当您完成调试进程内的脚本从进程中分离。   ======
从ps6.2 rc1开始:
Enter-PSHostProcess 新增-CustomPipeName参数,这样就【不需要总变化的进程id】了。 powershell进程1:
pwsh -custompipename mypipe powershell进程2:
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:】盘符 Enable-ExperimentalFeature -Name PSUseAbbreviationExpansion
后,将增加长命令的驼峰缩写
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 - 仅引用需要它的字段(它们包含分隔符)。
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V7.0pr1 ████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛   在脚本中,管道符可以放在行首,原来只能在行尾。 原来:
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() [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 PS /root> 'a b c d' -split ' ',-3
a b
c
d   ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview3 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
新增并发参数
| ForEach-Object -Parallel 例子:
1
get-content ip.txt |foreach-object -Parallel{ ping.exe $_  } 2
Get-Content /powershell/ip.txt |ForEach-Object -Parallel {if (Test-Connection -Count 1 -TargetName $_ -Quiet) {$_} } 6>$null 3
$c = 123
$a = 1..100
$a | ForEach-Object -ThrottleLimit 5  -Parallel {
 Write-Host $_
 Start-Sleep -Seconds 3
#这里调用函数,必须在这里定义。不能在外部定义。因为这是一个单独的线程。不支持执行代码块。支持调用脚本。
 $c1 = $using:c #变量要先克隆到线程内,再计算
}
参数:
-Parallel
-ThrottleLimit
-TimeoutSeconds
-AsJob   手册:
https://docs.microsoft.com/zh-cn/powershell/module/Microsoft.PowerShell.Core/ForEach-Object?view=powershell-7     ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview3 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛ Select-String -raw 默认会输出行号,
加上这个参数,只输出匹配。   ----------------------------------------------------------------   还有些细小的特性,我可能忘记添加在这里,欢迎提醒我补充,谢谢观看。   此贴不定期更新,更新新特性。       ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview4 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛   新增三目运算符
$变量名 = 表达式 ? 判断为真时运行的语句 : 判断为假时运行的语句   $message = (Test-Path $path) ? "Path exists" : "Path not found"   return $blackList -contains $target ? (Block-Target $target) : (Register-Target $target)   ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview4 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛   -ErrorAction
-WarningAction $DebugPreference,
$ErrorActionPreference,
$InformationPreference,
$ProgressPreference,
$VerbosePreference, 新增 'break' 枚举值,用于立即进入调试器。
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview4 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛   Invoke-DSCResource 支持绕过LCM(本地配置管理器), 从这个版本开始,linux下支持:
ps1----》mof     ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview5 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛   '前面的指令成功' && '则运行后面的指令';
1/0  && '因为前面的指令失败则后面的不运行'
'前面的指令失败' || '则运行后面的指令';
1/0  || '因为前面的指令失败则后面的运行'   1/0 && '成功' || '失败'
#类似于 if (1/0) {'成功'}else {'失败'} ,但不完全一样。
RuntimeException: Attempted to divide by zero.
失败
【??】的本质是一种if跳转。
左侧是null,则执行右侧。
左侧非null,则执行左侧。   $a ??= 1
左侧的变量值不是$null时,才为变量赋值。   ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview5 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛ Format-Hex 更新 ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview5 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛   Select-String 默认以反色突出显示。
若想要旧的不反色显示,加上参数-NoEmphasis
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview5 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛   $ErrorView 从NormalView变成ConciseView。
报错信息省略了,错误脚本行号。
$ErrorView = 'NormalView'  新增命令:Get-Error
以formatlist的形式,显示最近的报错信息列表。     ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview6 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛   Invoke-WebRequest和Invoke-RestMethod
新增-SkipHttpErrorCheck参数,
新增-ResponseStatusVariable参数
可以不同时使用。   ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview6 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛   get-counter监控命令,
Out-Printer
Update-List
回归 ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview6 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛   linux新增Get-Clipboard和Set-Clipboard ----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview6 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛   新增幺蛾子运算符
空条件运算符?.和?[]   (#10960)
?.方法名()  不会报错
'abc'?.toupper()?.tulower()  #我测试不灵   ${xxx}.?[2] 不会报错