当前位置: 移动技术网 > IT编程>开发语言>.net > powershell6,7新特性

powershell6,7新特性

2019年09月11日  | 移动技术网IT编程  | 我要评论

婚车装饰图片,陈达恒,omgvstpa

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 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网