Accessing only recently changed/committed files in TFS 2019

Hello team,

 

Can someone please let me know how to access and retrieve only the most recent files (.bar files) when they get checked in under specific project folder in TFS 2019 version? I’ve tried different attempts by using different TFS based cmdlets which I’ve found during my research recently but it looks like the PS engine doesn’t recognized them as a proper cmdlet in any PS 5.0+ versions for TFS 2019. For instance,

select *.bar -r -version “LmyBuildLabel~T” -all | select-tfsitem | select path | out-file ChangedBARFiles.txt

OR

Get-TfsChangeSet . -r | Where {$_.CheckinDate -eq (Get-Date)} |
Select TargetServerItem > recentlyChangedFiles.txt

 

Output:

“The term ‘tfs-item’ is not recognized as the name of a cmdlet…”

“The term ‘TFSChangeSet’ is not recognized as the name of a cmdlet…”

 

Also tried with another TFS cmdlet like:

Get-TfsChildItem . -r | Where {$_.CheckinDate -gt (Get-Date)}

Output:

“Get-TfsChildItem : The term ‘Get-TfsChildItem’ is not recognized as the name…”

 

 

Any help would be greatly appreciated.

 

Thanks!

 

 

 

The errors you are getting are basically saying that you have not Imported the commands into the Powershell session. I’ve not used Powershell with TFS, but most of the code I see uses a PSSnapIn, which is a bit deprecated. Take a look at this example and ensure that you can successfully import the PSSnapIn prior to executing the commands:

https://www.locktar.nl/programming/download-files-tfs-server-powershell/

There are also some Modules available for 2015, but from what I can gather most are interfacing with an API whereas the SnapIn is referencing a DLL installed:

PS C:\Users\rasim> Find-Module *tfs*

Version    Name                                Repository           Description
-------    ----                                ----------           -----------
4.2.6      NTFSSecurity                        PSGallery            Windows PowerShell Module for managing file and ...
1.4.1      cNtfsAccessControl                  PSGallery            The cNtfsAccessControl module contains DSC resou...
1.0.0.894  TfsCmdlets                          PSGallery            PowerShell Cmdlets for TFS and VSTS
2016.10.20 TFS                                 PSGallery            Control TFS 2015 via REST interface
0.1.0.100  PSPlus.Tfs                          PSGallery            Team foundation server related cmdlets!
1.0.0.0    TfsCmdlets2015                      PSGallery            PowerShell cmdlets for TFS 2015
0.4.0      TFSPowershell                       PSGallery            Functions to handle TFS Entities.
1.1.12.0   Tecman.Tfs.Tools                    PSGallery            Functions to support Microsoft Dynamics 365 Busi...
1.0.171... PSDT.Tfs                            PSGallery            A collection of Team Foundation Server related P...
5.2.0      FC_TFS                              PSGallery            Contains functions to interact with TFS Rest API
1.0        cEPRSInstallTFS2015                 PSGallery            cEPRSInstallTFS2015 Module helps in Instlling TFS
1.0        NTFSPermissionMigration             PSGallery            This module is used as a wrapper to the popular ...

Hopefully this points you in the right direction.

Thanks Rob. You’re right that I’ve missed out a PSSnapIn cmdlet first through which I could have imported the TFS based assembly first into the PS session. But the issue I’m facing now is that if I use the following cmdlet into my script:

“Add-PSSnapin Microsoft.TeamFoundation.PowerShell”

Output:

Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version.

And upon using 'Get-PSSnapin; cmdlet, it returns with just one module that is installed on the build server/agent:

Name : Microsoft.PowerShell.Core
PSVersion : 5.1.14393.3053
Description : This Windows PowerShell snap-in contains cmdlets used to manage
components of Windows PowerShell.
After doing some research, came to know that it has something to do with installing/re-installing Power Tools 2015 (tftp.exe) downloaded from here:
https://marketplace.visualstudio.com/items?itemName=TFSPowerToolsTeam.MicrosoftVisualStudioTeamFoundationServer2015Power
But when installed on the build agent, the PowerShell option is already included in it with 'Full' install option. And during Custom option, the PowerShell component doesn't come up to modify. The following component is shown up only during the 'Modify' option:
'Storyboard Shapes Authoring Tool'
Note:
Build Agent/Server info:
"Windows 2012 R2" , 64-bit OS
Thanks.