简体   繁体   中英

Using Powershell parameters in pipe command

I have this Powershell script which iterates through this folder's directories and runs git log .

However I cannot figure out how to get the $author parameter through to the git command.

Param(
  [string]$author,
  [string]$since
)
Get-ChildItem | ? { $_.PSIsContainer } | % { Push-Location $_.FullName; Write-Host "--" (Get-Location);`
git --no-pager log --author=$author --since='1 friday ago' --until='now' --format='%Cgreen%cr%Creset %s%Creset' --graph --decorate;`
Pop-Location }

Given this script:

# Log.ps1
Param(
    [string]$author
)

Get-ChildItem -Directory | % { Push-Location $_.FullName; git --no-pager log --author=$author; Pop-Location }

Invoking it like this yields the correct result:

.\Log.ps1 "SomeAuthor"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM