|
|
|
param ( |
|
$projectfile = "projects.csv", # list of projects to export |
|
$folderPath = "D:\Git1", |
|
$searchText = "Git export complete in", |
|
$analysisFile = "analysis.csv", |
|
$org = "myorg", |
|
$exportDate ="2025/11/13", |
|
$failedProjectFile = "failedprojects.csv", |
|
$outdatedProjectFile = "outdatedprojects.csv" |
|
) |
|
|
|
try { |
|
|
|
write-host "Assumes gh auth login has been run" -ForegroundColor Green |
|
write-host "Assumes (VSS) SS environment variables SSDIR, SSUSER & SSPWD have been set" -ForegroundColor Green |
|
|
|
# Validate folder path |
|
if (-not (Test-Path -Path $folderPath -PathType Container)) { |
|
throw "Folder path '$folderPath' does not exist." |
|
} |
|
|
|
write-host "Load the list of projects to export from $projectfile" |
|
$projectData = Import-Csv -Path $projectfile |
|
|
|
# create the analysis file |
|
Set-Content -Value "VSSProject,VSS2GITSuccess,Time,GitHubproject,GitHubSuccess,LastVSSCheckin,UpToDate" -path $folderPath\$analysisFile |
|
$processed = 0 |
|
$processSuccessful = 0 |
|
$outofdate = 0 |
|
|
|
# create the failed and outdated project file |
|
set-Content -Value "vss,gitrepo,migrate" -path $folderPath\$failedProjectFile |
|
set-Content -Value "vss,gitrepo,migrate" -path $folderPath\$outdatedProjectFile |
|
|
|
foreach ($project in $projectData) { |
|
if (([string]::IsnullorEmpty($project.gitrepo) -eq $false) -and ($project.migrate -eq $true)) { |
|
$source = $($project.vss) |
|
$target = $($project.gitrepo) |
|
|
|
# create the reprocess line in case it is needed |
|
$reproccesrow = $source + "," + $target + ", true" |
|
|
|
write-host "Checking VSS project $source'" -ForegroundColor Cyan |
|
$processed ++ |
|
$file = "$folderPath\$target.log" |
|
try { |
|
write-host " Loading file $file" |
|
$vss2gitsuccess = $false |
|
$githubsuccess = $false |
|
$exportupdatodate = $false |
|
$time = '00:00:00' |
|
|
|
# Read file content safely |
|
$content = Get-Content -Path $file -ErrorAction Stop |
|
|
|
# Search for the text |
|
$line = $content | Where-Object { $_ -match [regex]::Escape($searchText) } |
|
|
|
if ($line) { |
|
|
|
# Extract the time using regex (format HH:MM:SS) |
|
if ($line -match "\b\d{2}:\d{2}:\d{2}\b") { |
|
$vsstime = $matches[0] |
|
Write-Host " VSS2Git check for export OK from: $file in $vsstime" |
|
$vss2gitsuccess = $true |
|
} else { |
|
Write-Output " VSS2Git Export OK, but no time found in the line." -ForegroundColor Red |
|
} |
|
|
|
} else { |
|
Write-Host " VSS2Git no success message in: $file" -ForegroundColor Red |
|
} |
|
} |
|
catch { |
|
Write-Host " Error reading file: $file - $_" -ForegroundColor Red |
|
} |
|
|
|
# Check if the repository is empty (no default branch or no commits) |
|
try { |
|
# Get the default branch name |
|
write-host " Checking GitHub for $org/$target" |
|
$defaultBranch = & "D:\gh-cli\gh" repo view "$org/$target" --json defaultBranchRef -q ".defaultBranchRef.name" 2>$null |
|
|
|
if (-not $defaultBranch) { |
|
Write-Host " GitHub Repository $org/$target exists but is empty (no default branch)." -ForegroundColor Yellow |
|
} elseif ( $defaultBranch -ne "main") { |
|
Write-Host " GitHub Repository $org/$target exists but has wrong branch name ($defaultBranch)." -ForegroundColor Yellow |
|
} else { |
|
Write-Host " Gihub Repository $org/$target exists and has content." |
|
$githubsuccess = $true |
|
} |
|
} |
|
catch { |
|
Write-Host " Error checking repository content: $_" -ForegroundColor Red |
|
} |
|
|
|
# Check if more recent VSS updates |
|
try { |
|
# Get the default branch name |
|
write-host " Checking for last VSS update for $source" |
|
$ssresult = & 'C:\Program Files (x86)\Microsoft Visual SourceSafe\ss.exe' history "$source" -#1 -r |
|
$rows = $ssresult.Split("`n") |
|
$daterow = "" |
|
foreach ($r in $rows) { |
|
if ($r.contains("Date:")) { |
|
$daterow = $r |
|
break |
|
} |
|
} |
|
if ($daterow -match 'Date:\s*(\d{1,2}/\d{1,2}/\d{2})\s*Time:\s*(\d{1,2}:\d{2})') { |
|
$date = $matches[1] # first capture group -> 15/08/17 |
|
$time = $matches[2] # second capture group -> 9:22 |
|
# Combine date and time into a single variable |
|
$datetimeObject = [datetime]::ParseExact("$date $time", "d/MM/yy H:mm", $null) |
|
|
|
# Check for updates |
|
write-host (" Last VSS update $datetimeObject") |
|
if ([datetime]$exportDate -gt $datetimeObject) { |
|
Write-Host " Export up to date, no changes changes in VSS since $($datetimeObject.ToString("d/MM/yy H:mm")) " -ForegroundColor Green |
|
$exportupdatodate = $true |
|
} else { |
|
Write-Host " Export out of date, newest changes in VSS was at $($datetimeObject.ToString("d/MM/yy H:mm"))" -ForegroundColor Yellow |
|
$outofdate ++ |
|
} |
|
} else { |
|
Write-Host " Date and time not found for last VSS export " -ForegroundColor Red |
|
|
|
} |
|
} |
|
catch { |
|
Write-Host " Error checking repository content: $_" -ForegroundColor Red |
|
} |
|
|
|
if ($vss2gitsuccess -and $githubsuccess) { |
|
$processSuccessful ++ |
|
} else { |
|
add-Content -Value $reproccesrow -path $folderPath\$failedProjectFile |
|
} |
|
|
|
if ($exportupdatodate -eq $false) { |
|
add-Content -Value $reproccesrow -path $folderPath\$outdatedProjectFile |
|
} |
|
|
|
Add-Content -Value "$source,$vss2gitsuccess,$vsstime,$target,$githubsuccess,$($datetimeObject.ToString("d/MM/yy H:mm")),$exportupdatodate" -path $folderPath\$analysisFile -Force |
|
} |
|
|
|
} |
|
Write-host "Processed: $processed" |
|
write-host "Processing Unsuccessful: $($processed - $processSuccessful)" |
|
write-host "Processing Successful: $processSuccessful" |
|
write-Host "VSS Export Out of Date: $outofdate" |
|
|
|
} |
|
catch { |
|
Write-Host "Script error: $_" -ForegroundColor Red |
|
} |