Created
January 21, 2011 00:42
-
-
Save jstangroome/789034 to your computer and use it in GitHub Desktop.
Change TFS workspace file stamps to match server check-in times
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -version 2.0 | |
[CmdletBinding()] | |
param ( | |
[string] | |
$Path = ((Get-Location).ProviderPath) | |
) | |
$ErrorActionPreference = 'Stop' | |
Set-StrictMode -Version Latest | |
Add-Type -AssemblyName 'Microsoft.TeamFoundation.VersionControl.Client, Version=10.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a' | |
$WorkstationType = [Microsoft.TeamFoundation.VersionControl.Client.Workstation] | |
if (-not $WorkstationType::Current.IsMapped($Path)) { | |
throw 'Path is not part of a TFS workspace.' | |
} | |
$Info = $WorkstationType::Current.GetLocalWorkspaceInfo($Path) | |
$Collection = New-Object -TypeName Microsoft.TeamFoundation.Client.TfsTeamProjectCollection -ArgumentList $Info.ServerUri | |
$Collection.EnsureAuthenticated() | |
$Workspace = $Info.GetWorkspace($Collection) | |
$ItemSpec = New-Object -TypeName Microsoft.TeamFoundation.VersionControl.Client.ItemSpec -ArgumentList $Path, Full | |
$Workspace.GetExtendedItems(@($ItemSpec), 'NonDeleted', 'File') | | |
% { $_ } | #unroll multidimensional array | |
Where-Object { | |
$_.ChangeType -eq 'None' -and | |
($_.LocalItem | Test-Path) | |
} | | |
ForEach-Object { | |
$Item = $_.LocalItem | Get-Item | |
if ($Item.LastWriteTime -ne $_.CheckinDate) { | |
try { | |
$Item.IsReadOnly = $false | |
$Item.LastWriteTime = $_.CheckinDate | |
} finally { | |
$Item.IsReadOnly = $true | |
} | |
$Item | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment