














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
}
我原创 分享! 2016-12-02
if ($PSEdition -eq 'Desktop')
{
#win
}
if ($PSEdition -eq 'Core')
{
#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
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。