加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

Windows – 每个开发人员应该知道的PowerShell脚本

发布时间:2020-12-14 04:32:02 所属栏目:Windows 来源:网络整理
导读:Windows PowerShell现在已经很久了.与老旧的windows shell相比,功能更强大. 您是否有任何脚本来加快和简化您作为开发人员的日常工作?如果你能用PowerShell做魔术 – 请与我们分享! 更新 不是一个脚本,而且非常有用的是PowerShell Community Extensions.该
Windows PowerShell现在已经很久了.与老旧的windows shell相比,功能更强大.
您是否有任何脚本来加快和简化您作为开发人员的日常工作?如果你能用PowerShell做魔术 – >请与我们分享!

更新
不是一个脚本,而且非常有用的是PowerShell Community Extensions.该软件包包含了很多新的Cmdlet和PowerShell修改.

我在命令行中放置了一堆脚本与Subversion一起使用.他们大多数只是使用–xml选项来以对象形式放置各种信息.这里有几个例子:
function Get-SvnStatus( [string[]] $Path   = ".",[string]   $Filter = "^(?!unversioned|normal|external)",[switch]   $NoFormat )
{
    # powershell chokes on "wc-status" and doesn't like two definitions of "item"
    [xml]$status = ( ( Invoke-Expression "svn status $( $Path -join ',' ) --xml" ) -replace "wc-status","svnstatus" ) `
        -replace "item=","itemstatus="

    $statusObjects = $status.status.target | Foreach-Object { $_.entry } | Where-Object { 
        $_.svnstatus.itemstatus -match $Filter 
    } | Foreach-Object {
        $_ | Select-Object @{ Name = "Status"; Expression = { $_.svnstatus.itemstatus } },@{ Name = "Path";   Expression = { Join-Path ( Get-Location ) $_.path } }
    } | Sort-Object Status,Path

    if ( $NoFormat )
    {
        $statusObjects
    }
    else
    {
        $statusObjects | Format-Table -AutoSize
    }
}

function Get-SvnLog( [string] $Path = ".",[int]    $Revision,[int]    $Limit = -1,[switch] $Verbose,[switch] $NoFormat )
{
    $revisionString = ""
    $limitString = ""
    $verboseString = ""

    if ( $Revision )
    {
        $revisionString = "--revision $Revision"
    }

    if ( $Limit -ne -1 )
    {
        $limitString = "--limit $Limit"
    }

    if ( $Verbose )
    {
        $verboseString = "--verbose"
    }

    [xml]$log = Invoke-Expression "svn log $( $path -join ',' ) --xml $revisionString $limitString $verboseString"

    $logObjects = $log.log.logentry | Foreach-Object {
        $logEntry = $_

        $logEntry | Select-Object `
            @{ Name = "Revision"; Expression = { [int]$logEntry.revision } },@{ Name = "Author"; Expression = { $logEntry.author } },@{ Name = "Date"; 
               Expression = {
                   if ( $NoFormat )
                   {
                       [datetime]$logEntry.date
                   }
                   else
                   {
                       "{0:dd/MM/yyyy hh:mm:ss}" -f [datetime]$logEntry.date
                   }
               } },@{ Name = "Message"; Expression = { $logEntry.msg } } | 
        Foreach-Object {
            # add the changed path information if the $Verbose parameter has been specified
            if ( $Verbose )
            {
                $_ | Select-Object Revision,Author,Date,Message,@{ Name = "ChangedPaths"; 
                       Expression = {
                           $paths = $logEntry.paths.path | Foreach-Object {
                               $_ | Select-Object `
                                   @{ Name = "Change"; 
                                      Expression = { 
                                          switch ( $_.action )
                                          {
                                              "A" { "added" }
                                              "D" { "deleted" }
                                              "M" { "modified" }
                                              "R" { "replaced" }
                                              default { $_.action }
                                          }
                                      } },@{ Name = "Path"; Expression = { $_."#text" } }
                           }

                           if ( $NoFormat )
                           {
                               $paths
                           }
                           else
                           {
                               ( $paths | Sort-Object Change | Format-Table -AutoSize | Out-String ).Trim()
                           }
                       } 
                     }
            }
            else
            {
                $_
            }
        }
    }

    if ( $NoFormat )
    {
        $logObjects
    }
    else
    {
        $logObjects | Format-List
    }
}

我有这些别名svns和svnl分别.我谈了几个人here.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读