diff --git a/Generate Egnyte Export.sql b/Generate Egnyte Export.sql index fb5e646..451a636 100644 --- a/Generate Egnyte Export.sql +++ b/Generate Egnyte Export.sql @@ -1,24 +1,35 @@ -- Generate Non-Duplicated PARENT FOLDER List DROP TABLE DataInventory; CREATE TABLE DataInventory AS -SELECT SERVER, - REPLACE( - Parent, - "X:\"," \ \ mpe.ca \ datadrive \ ") AS UNCPath, - REPLACE(REPLACE(Parent,(" X: \ " || Server)," / Shared / N - Data ")," \ "," / ") AS EgnytePath, - sum(FileCount), Sum(FileSize), 'Parent' as Source from FolderData -Where Parent not in ( - SELECT Parent FROM DuplicateList +Select * from ( + SELECT SERVER,Parent, + REPLACE( + Parent, + "X:\"," \\mpe.ca\datadrive\") AS UNCPath, + REPLACE(REPLACE(Parent,("X:\" || Server),"/Shared/N-Data"),"\","/") AS EgnytePath, + sum(FileCount), Sum(FileSize), 'Parent' as Source from FolderData + Where Parent != ( + SELECT Parent FROM DuplicateList + ) +GROUP by UNCPath ) UNION -SELECT SERVER, - REPLACE(PATH," X: \ "," \ \ mpe.ca \ datadrive \ ") AS UNCPath, - REPLACE(REPLACE(PATH,(" X: \ " || Server)," / Shared / N - Data ")," \ "," / ") AS EgnytePath, - sum(FileCount), Sum(FileSize), 'Project' as Source from FolderData -Where Project not in ( - SELECT A.Project FROM NonDupProject as A) -AND Parent not in ( - Select B.Parent FROM NonDupParent as B - ) -group by Server -ORDER BY Server; \ No newline at end of file +SELECT SERVER, Parent, + REPLACE(PATH," X:\","\\mpe.ca\datadrive\") AS UNCPath, + REPLACE(REPLACE(PATH,("X:\" || Server),"/Shared/N-Data"),"\","/") AS EgnytePath, + FileCount, FileSize, 'Project' as Source from FolderData +Where FolderData.Project NOT in ( + SELECT A.Project FROM DuplicateList as A) +AND FolderData.Parent in ( + Select B.Parent FROM DuplicateList as B + ); + + +delete FROM DataInventory +where Parent in ( + select Parent from DataInventory + group by Parent + HAVING count(*) > 1 + ) +and Source = 'Project'; + diff --git a/Get-ProjectFolders.ps1 b/Get-ProjectFolders.ps1 index 6f83abf..801871f 100644 --- a/Get-ProjectFolders.ps1 +++ b/Get-ProjectFolders.ps1 @@ -221,7 +221,7 @@ if ($sql_result) { ## Generate Egnyte Data Inventory Sheet -$OutFile = $OutputFolder + "\MPE Data Inventory " + (Get-Date -Format FileDateTime) + ".xlsx" +$OutFile = $OutputFolder + "\MPE Data Inventory " + (Get-Date -Format FileDate) + ".xlsx" try { Remove-Item -Path $OutFile -Force -ErrorAction SilentlyContinue