param( [string]$Source = '\\phpsrv03\NBIM\code\CS\P_Rec_BOP\repo', [string]$Output = 'C:\dev\autodesk\migration\audits\p-rec-bop-plant3d-2019' ) $ErrorActionPreference = 'Stop' $evidence = Join-Path $Output 'evidence' New-Item -ItemType Directory -Force -Path $evidence | Out-Null function Rel([string]$path) { $path.Substring($Source.Length).TrimStart('\','/') } function Hash([string]$path) { (Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash } function Classify([string]$extension) { switch ($extension.ToLowerInvariant()) { '.cs' { 'source' }; '.vb' { 'source' }; '.fs' { 'source' } '.sln' { 'project' }; '.csproj' { 'project' }; '.vbproj' { 'project' }; '.props' { 'project' }; '.targets' { 'project' }; '.config' { 'configuration' }; '.json' { 'configuration' } '.doc' { 'template/document' }; '.docx' { 'template/document' }; '.dot' { 'template/document' }; '.dotx' { 'template/document' }; '.dotm' { 'template/document' }; '.rtf' { 'template/document' } '.dll' { 'binary' }; '.arx' { 'binary' }; '.dbx' { 'binary' }; '.cuix' { 'binary' } '.resx' { 'resource' }; '.png' { 'resource' }; '.jpg' { 'resource' }; '.bmp' { 'resource' }; '.ico' { 'resource' } default { 'other' } } } $files = Get-ChildItem -LiteralPath $Source -Recurse -File | Sort-Object FullName $inventory = foreach ($file in $files) { [pscustomobject]@{ RelativePath = Rel $file.FullName; Extension = $file.Extension.ToLowerInvariant(); Category = Classify $file.Extension; Length = $file.Length; LastWriteTimeUtc = $file.LastWriteTimeUtc.ToString('o') } } $inventory | Export-Csv (Join-Path $evidence 'file-inventory.csv') -NoTypeInformation -Encoding UTF8 $hashes = foreach ($file in $files) { [pscustomobject]@{ RelativePath = Rel $file.FullName; Length = $file.Length; SHA256 = Hash $file.FullName } } $hashes | Export-Csv (Join-Path $evidence 'hashes.csv') -NoTypeInformation -Encoding UTF8 $projectFiles = $files | Where-Object { $_.Extension -in '.sln','.csproj','.vbproj','.props','.targets','.config','packages.config','packages.lock.json' } | ForEach-Object { Rel $_.FullName } $projectFiles | Set-Content (Join-Path $evidence 'project-files.txt') -Encoding UTF8 $sourceFiles = $files | Where-Object { $_.Extension -in '.cs','.vb','.fs' } function Search([string]$name, [string]$pattern, [string[]]$paths = @('*.cs','*.csproj','*.config','*.xml','*.json','*.md','*.txt')) { $arguments = @('-n','--no-heading','--hidden','--glob','!.git/**','--glob','!**/lib/**','--glob','!**/bin/**','--glob','!**/obj/**') foreach ($path in $paths) { $arguments += @('--glob', $path) } $arguments += @($pattern, $Source) $result = & rg @arguments 2>$null if ($LASTEXITCODE -ne 0 -and $null -eq $result) { $result = 'NO_MATCH' } $result | ForEach-Object { $_.ToString().TrimEnd() } | Set-Content (Join-Path $evidence $name) -Encoding UTF8 } Search 'commands-search.txt' 'CommandMethod|IExtensionApplication|Initialize\(|Terminate\(|ExtensionApplication|CommandClass|PlantApplication|ProjectManager|DataLinksManager|PnPDatabase|PnPTable|PnPRow|ConnectionManager|ContentManager' Search 'plant-api-search.txt' 'Autodesk\.AutoCAD|Autodesk\.ProcessPower|PlantInstance|PlantProject|DataLinks|PnP|ProjectManager|EngineeringItems|PipingComponents|PipeLines|LineGroup|DrawingProperties' Search 'word-api-search.txt' 'Microsoft\.Office\.Interop\.Word|Microsoft\.Office\.Core|Word\.Application|Word\.Document|Word\.Range|Documents\.Open|Documents\.Add|SaveAs2?|ExportAsFixedFormat|InsertFile|FormattedText|Bookmarks|ContentControls|Tables|Rows\.Add|Cells|Find\.Execute|Fields\.Update|Repaginate|Sections|Headers|Footers|StoryRanges|Selection|Clipboard|PasteSpecial|SautinSoft|DocumentFormat\.OpenXml' Search 'template-search.txt' '\.docx?|\.dotx?|\.dotm|template|шаблон|образец|бланк|Word' Search 'paths-and-settings-search.txt' '^[^:]+:[0-9]+:.*([A-Za-z]:\\|\\\\|Settings\.xml|App\.config|Registry|Environment\.GetEnvironmentVariable|GetFolderPath)' Search 'database-and-io-search.txt' 'SQLite|System\.Data|SELECT |INSERT |UPDATE |DELETE |File\.Read|File\.Write|StreamWriter|Xml|CSV|Excel|XLS|HTTP|WebClient|HttpClient' $referenceRows = foreach ($project in ($files | Where-Object Extension -eq '.csproj')) { try { [xml]$xml = Get-Content -LiteralPath $project.FullName -Raw foreach ($reference in $xml.SelectNodes("//*[local-name()='Reference']")) { [pscustomobject]@{ Project = Rel $project.FullName; Kind = 'Reference'; Name = [string]$reference.Include; HintPath = [string]$reference.HintPath; CopyLocal = [string]$reference.Private } } foreach ($reference in $xml.SelectNodes("//*[local-name()='ProjectReference']")) { [pscustomobject]@{ Project = Rel $project.FullName; Kind = 'ProjectReference'; Name = [string]$reference.Include; HintPath = ''; CopyLocal = '' } } foreach ($package in $xml.SelectNodes("//*[local-name()='PackageReference']")) { [pscustomobject]@{ Project = Rel $project.FullName; Kind = 'PackageReference'; Name = [string]$package.Include; HintPath = [string]$package.Version; CopyLocal = '' } } } catch { [pscustomobject]@{ Project = Rel $project.FullName; Kind = 'ParseError'; Name = $_.Exception.Message; HintPath = ''; CopyLocal = '' } } } $referenceRows | Export-Csv (Join-Path $evidence 'project-references.csv') -NoTypeInformation -Encoding UTF8 $templateRows = foreach ($file in ($files | Where-Object { $_.Extension -in '.doc','.docx','.dot','.dotx','.dotm','.rtf' })) { [pscustomobject]@{ RelativePath = Rel $file.FullName; Format = $file.Extension.ToLowerInvariant(); Length = $file.Length; SHA256 = Hash $file.FullName; SourceModified = $false } } $templateRows | Export-Csv (Join-Path $evidence 'template-files.csv') -NoTypeInformation -Encoding UTF8 $sourceGit = if (Test-Path -LiteralPath (Join-Path $Source '.git')) { & git -C $Source status --short; & git -C $Source branch --show-current; & git -C $Source rev-parse HEAD; & git -C $Source log -1 --format=fuller; & git -C $Source remote -v } else { 'NO_GIT_DIRECTORY' } $sourceGit | Set-Content (Join-Path $evidence 'source-git.txt') -Encoding UTF8 Get-ChildItem -LiteralPath $Source -Directory | Select-Object -ExpandProperty Name | Set-Content (Join-Path $evidence 'top-level-directories.txt') -Encoding UTF8 $inventory | Group-Object Category | Sort-Object Name | ForEach-Object { "{0}`t{1}" -f $_.Name,$_.Count } | Set-Content (Join-Path $evidence 'inventory-summary.txt') -Encoding UTF8