ps1 基础

禁止对@进行特殊处理,当做splat 操作
就是加上引号

curl --request POST  -H "@cheader.txt" --form "pushfile=@path/to/data.zip" 127.0.0.1:3000/uploadfile

获取指定网卡的IPV4地址

使用ipconfig获取到网卡的名字

$ipo = Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias "网卡的名字"
($ipo|out-string -stream| sls -Pattern "IPAddress"|out-string).Split(":")[-1]

递归删除文件夹

Remove-Item ~/dir/* -recurse

在命令中使用环境变量

Remove-Item $env:ENV_VAR/* -recurse

运行时间

$start = Get-Date

do your job

$end = Get-Date
Write-Host -ForegroundColor Red ('Total Runtime: ' + ($end - $start).TotalSeconds)
powershell -Command start www.baidu.com

管理员身份运行程序,同时设置执行策略
pwsh -ExecutionPolicy AllSigned  -Command Start-Process wt -Verb runAs
pwsh -ExecutionPolicy Unrestricted  -Command Start-Process wt -Verb runAs


Allow all scripts 	                                Unrestricted
Allow local scripts and remote signed scripts 	    RemoteSigned
Allow only signed scripts 	                        AllSigned

https://stackoverflow.com/questions/5571579/escaping-splatted-variables-in-powershell-invoke-expression

posted @ 2020-09-16 15:44  fndefbwefsowpvqfx  阅读(138)  评论(0编辑  收藏  举报