且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Powershell(2)

更新时间:2022-08-12 16:15:52

powershell(2)

帮助系统(显示出来的参数语法要比Unix中help复杂)

  1. save-help -destinationpath c:\help
  2. update-help -force -sourcepath c:\help
  3. get-command -noun *log* -verb get -commandtype cmdlet|all|application
  4. [-arg] 为位置参数, 必须写在特定的位置
  5. [[-arg]] 可选又位置, 可以不写, 但是写了就要在特定的位置
  6. -arg 不是位置参数, 一定要写, 但是对位置没有要求
  7. (get-content C:\demp.txt) ()中的优先级高, 强制限制性, 与Unix不同, Unix中是打开一个子shell执行
  8. 在每一个帮助信息中的参数都有[

注意

  • 在windows中为了统一filesystem, wsman, registry等, 通过交item, 文件和文件夹叫item

其他命令

  • out-file
    • -append
    • -width
    • -path
  • write-eventlog
  • write-output
  • convertTo-html
  • new-alias
    • export-alias
    • import-alias
  • show-command 图形显示, 并且可以执行命令
  • test-connection: ping
  • get-netfirewallrule
    • -direct inbound|outbound
  • get-psprovider|get-psdrive: 显示所有的提供程序, wsman, filesystem, register, alias, environment
  • get-childitem
    • new-item
    • remove-item
    • set-item
    • set-itemproperty: 设置属性, 一般配置get-itemproperty使用
    • get-item
      • -filter: 过滤掉指定的项
  • -literakpath: 不支持通配符
  • out-gridview: 将输入发送到图形界面上显示
  • export-cvs:
    • export-clixml
      • -delimiter
  • format-custom: 展开层级

实验(1)

  • get-process | sort-object -property vm -decending | select-obejct -index 0,1,2,3,4 消耗内存前五名
  • get-services | select-object -property name, status | sort-object -property status -descending | export-csv services.csv
  • set-service -name bits -startiuptype manual
  • get-history -id 5 | invoke-history
  • new-eventlog -logname game -source cs 添加应用日志