zoukankan      html  css  js  c++  java
  • Windows Powershell基础知识点

    Powershell基础知识点

    1、Powershell脚本文件的文件名以.PS1扩展(注意是数字的1)

    2、Powershell执行策略
       默认为Restricted,可以通过下面的cmdlet命令获取当前执行策略:
       Get-ExecutionPolicy
       可选的执行策略有如下:
       Restricted - 脚本不能运行
       RemoteSigned - 本地创建的脚本可以运行,但从网上下载的脚本不能运行(除非它们拥有由受信任的发布者签署的数字签名)
       AllSigned - 仅当脚本由受信任的发布者签名才能运行
       Unrestricted - 脚本执行不受限制,不管来自哪里,也不管它们是否有签名
       可以用下面的cmdlet命令重新设置执行策略:
       Set-ExecutionPolicy <policy name>

    3、运行脚本
       需要键入脚本的完整路径,如d:\scripts\script.psi
       如果脚本文件刚好位于系统目录中,可以键入 .\script.psi 运行
       注意 .\ 不能省

    4、管道
       Get-Process | Sort-Object ID
       获取进程列表并按进程ID排序

    5、变量
       $a = Get-Process
       $b = (Get-Process | Sort-Object ID)

    6、@符号
       使用@符号可以把列表内容转换成数组,比如下面:
       $procs = @{name="explorer", "taskmgr"}
       Get-Process @procs
       第二行加@确保procs被当做数组处理

    7、split
       "This is a test" -split " "

    8、join
       "Hello","world" -join ","

    9、断点
       根据行号插入断点:
       New-PSBreakpint -Script d:\Scripts\Script.ps1 -Line 10
       即在脚本的第10行插入一个断点
       也可以将断点绑定到变量上:
       New-PSBreakpoint -Script d:\Scripts\Script.ps1 -variables a
       其他命令包括:
       Get-PSBreakpoint
       Enable-PSBreakpoint
       Disable-PSBreakpoint
       Remove-PSBreakpoint

    10、单步调试
       Step-Into
       Step-Out

  • 相关阅读:
    .NET:CLR via C# A Brief Look at Metadata
    在容器中运行 Jenkins pipeline 任务
    Azure AI 服务之文本翻译
    linux journalctl 命令
    容器化的 DevOps 工作流
    System V IPC 之消息队列
    System V IPC 之信号量
    System V IPC 之共享内存
    减小容器镜像的三板斧
    linux chroot 命令
  • 原文地址:https://www.cnblogs.com/feichexia/p/Powershell_Tips.html
Copyright © 2011-2022 走看看