2016-02-02 27 views
0

我正在嘗試編寫一個Powershell腳本,其中列出了由於錯誤而在TFS上更改的所有源文件。這個想法是那些被改變最多的文件是重構或重寫的候選文件。獲取導致Powershell出現大多數問題的項目

我發現script列出自日期以來更改的項目。

############################################################### 
#                
# Search for all unique file changes in TFS 
# for a given date/time range and collection location. 
# Write results to a manifest file.            
#                
# Author: Gary A. Stafford 
# Created: 2012-04-18 
# Revised: 2012-08-11       
#                
############################################################### 

# Clear Output Pane 
clear 

# Enforce coding rules 
Set-StrictMode -version 2.0 

# Loads Windows PowerShell snap-in if not already loaded 
if ((Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null) 
{ 
    Add-PSSnapin Microsoft.TeamFoundation.PowerShell 
} 

# Variables - CHECK EACH TIME 
[string] $tfsCollectionPath = "http://tfs2010/tfsCollection" 
[string] $locationToSearch = "$/Development/AdventureWorks/" 
[string] $outputFile = "c:\ChangesToTFS.txt" 
[string] $dateRange = "D2012-07-08 00:00:00Z~" 
[bool] $openOutputFile = $true # Accepts $false or $true 

# For a date/time range: 'D2012-08-06 00:00:00Z~D2012-08-09 23:59:59Z' 
# For everything including and after a date/time: 'D2012-07-21 00:00:00Z~' 

[Microsoft.TeamFoundation.Client.TfsTeamProjectCollection] $tfs = get-tfsserver $tfsCollectionPath 

# Add informational header to file manifest 
[string] $outputHeader = 
    "TFS Collection: " + $tfsCollectionPath + "`r`n" + 
    "Source Location: " + $locationToSearch + "`r`n" + 
    "Date Range: " + $dateRange + "`r`n" + 
    "Created: " + (Get-Date).ToString() + "`r`n" + 
    "======================================================================" 

$outputHeader | Out-File $outputFile 

Get-TfsItemHistory $locationToSearch -Server $tfs -Version $dateRange ` 
-Recurse -IncludeItems | 

Select-Object -Expand "Changes" | 
    Where-Object { $_.ChangeType -notlike '*Delete*'} | 
    Where-Object { $_.ChangeType -notlike '*Rename*'} | 

Select-Object -Expand "Item" | 
    Where-Object { $_.ContentLength -gt 0} | 

    Where-Object { $_.ServerItem -notlike '*/sql/*' } | 
    Where-Object { $_.ServerItem -notlike '*/documentation/*' } | 
    Where-Object { $_.ServerItem -notlike '*/buildtargets/*' } | 

    Where-Object { $_.ServerItem -notlike 'build.xml'} | 
    Where-Object { $_.ServerItem -notlike '*.proj'} | 
    Where-Object { $_.ServerItem -notlike '*.publish.xml'} | 

Select -Unique ServerItem | Sort ServerItem | 
Format-Table -Property * -AutoSize | Out-String -Width 4096 | 
Out-File $outputFile -append 

Write-Host `n`r**** Script complete and file written **** 

If ($openOutputFile) { Invoke-Item $outputFile } 

如果我修改這個劇本一點點,我得到的所有錯誤:

$bugs = Get-TfsItemHistory $locationToSearch -Server $tfs -Version $dateRange ` 
-Recurse -IncludeItems | Select-Object -ExpandProperty AssociatedWorkItems | Where-Object {$_.WorkItemType -eq 'Bug'} 

我的問題是把兩者結合起來。通過上面的腳本,上下文切換到工作項目。我怎樣才能列出符合由於錯誤而被更改的條件的源文件?

回答

0

根據您的信息,您可以列出作爲工作項目一部分而更改的所有文件。示例代碼如下:

​​
+0

該方法聽起來很有希望。但是,當我嘗試執行Get-TfsServer serverName -all時收到錯誤消息。錯誤是'get-tfsserver:無法加載文件或程序集'Microsoft.TeamFoundation,Version = 12.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其某個依賴項。給定的程序集名稱或代碼庫無效。 (來自HRESULT的異常:0x80131047) 在C:\ Scripts \ Get-Bugtroubled.ps1:24 char:5' – tobre

+0

根據你的錯誤信息:這是一個Cmdlet拋出錯誤。您需要將TFS Power Tools的版本與您的Visual Studio客戶端進行匹配。 ..... – Chamberlain