zoukankan      html  css  js  c++  java
  • Powershell点滴

    1. 如何表达枚举类型?
    [StringSplitOptions] $option = "None"
    [StringSplitOptions] $option = "RemoveEmptyEntries"
     
    2. 在bat中调用执行Powershell文件(相对路径)
    powershell.exe -Command "& {.\Script1.ps1}"
     
    3. 加入-NoExit参数执行ps1文件
    PowerShell.exe -NoExit "& 'C:\Program Files\...\sharepoint.ps1'"
     
    4. 通用参数-confirm -ErrorAction
    -Confirm $false
    -ErrorAction "SilentlyContinue"
     
    5. 创建对象并传递参数
    $date = New-Object -TypeName System.DateTime -ArgumentList @(1882,7,4,0,0,0)
     
    6. 创建COM对象
    $ie = New-Object -ComObject "InternetExplorer.Application"
     
    7. 执行Powershell脚本文件并传入命名参数
    #powershell -noexit -file "C:\Users\Terry\MyPSScripts\test01.ps1" -par1 "hello world" -par2 great
    在文件中有对参数的定义:param($par1, $par2)
     
    8. 获取给定路径的父目录
    split-path “c:\test\error.log” #会返回 c:\test, 等价于 split-path “c:\test\error.log” –Parent
    split-path “c:\test\error.log” -leaf #会返回 error.log
     
    9. 得到脚本文件所在的目录
    $MyInvocation.MyCommand.Path 比较好用
    $MyInvocation.InvocationName 不可靠,它可以是”&”也可以是实际的脚本全路径

  • 相关阅读:
    poj 3378 Crazy Thairs 夜
    1487. Chinese Football 夜
    容斥原理
    Dancing Links
    三角剖分
    模线性方程模板
    模线性方程
    容斥原理 POJ2773
    DNA Sequence [矩阵]
    hdu 2588 容斥
  • 原文地址:https://www.cnblogs.com/teamleader/p/2318706.html
Copyright © 2011-2022 走看看