PowerShell Tips

2020-07-08 • 预计阅读时间 1 分钟

PowerShell还是挺好用的,但是可以通过一些小的调整,增加便利性。

TotalCommander

在PowerShell可以通过ii .利用资源管理器打开当前目录。如果能够在TC中打开的话,那会方便很多了。

function tc { 
    $path =Get-Location
    Start-Process -NoNewWindow -FilePath "${Env:soft}\totalcmd\TOTALCMD64.EXE" -ArgumentList "$path","/O /T "

  }

需要提前通过$env:soft="D:\soft"来指定soft的环境变量是什么。后面如果想要打开TotalCommander的话,用tc就可以了

Microsoft VS Code Insiders

其实默认有Code了。但是用的是Insiders导致了code无法识别。只能自己调整一下了。

# 用code打开
function code {
    $code_path="${Env:LOCALAPPDATA}\Programs\Microsoft VS Code Insiders\Code - Insiders.exe"
    if ($args.Count -eq 0) {
        Start-Process -FilePath $code_path
    } else {
        Start-Process -FilePath $code_path -ArgumentList "$args"
    }
}

类似的也可以给Everedit增加一个快捷启动。

# 使用everedit打开
function ever {
    $code_path="${Env:soft}\EverEdit\EverEdit.exe"
    if ($args.Count -eq 0) {
        Start-Process -FilePath $code_path
    } else {
        Start-Process -FilePath $code_path -ArgumentList "$args"
    }
}

获取本机IP

获取本机网卡的上IP信息

  function myip {
    $ip = Get-NetIPAddress -AddressFamily IPv4 | where-object IPAddress -notmatch "^(169)|(127)" | Sort-Object IPAddress | select IPaddress,Interface*
    Write-Output $ip
      
  }

which

function which($param){
    (Get-Command $param).definition
}
softPowerShell

wentao

写点代码,解决点问题。

技术周报#1

微服务划分