44)
55
66$ModuleName = ' SqlServer-Version-Management' ;
7- $ModuleVersion = ' 2.1.165 ' ;
7+ $ModuleVersion = ' 2.1.166 ' ;
88$ModuleFiles = @ (
99 @ {
1010 FileName = ' SqlServer-Version-Management\SqlServer-Version-Management.psd1' ;
@@ -15,7 +15,7 @@ $ModuleFiles = @(
1515 " ModuleToProcess = @('SqlServer-Version-Management.psm1')" ,
1616 " " ,
1717 " # Version below is automatically incremented on build" ,
18- " ModuleVersion = `" 2.1.165 `" " ,
18+ " ModuleVersion = `" 2.1.166 `" " ,
1919 " " ,
2020 " GUID = 'dd03b53d-575a-4056-ae08-e6dfea3384ea'" ,
2121 " " ,
@@ -3874,11 +3874,13 @@ $ModuleFiles = @(
38743874 " `$ totalErrors=0;" ,
38753875 " `$ ret = @(); # errors" ,
38763876 " `$ successNames = @()" ,
3877+ " `$ successDetails = @()" ,
38773878 " `$ failDetails = @()" ,
38783879 " `$ quot1=[char]171; `$ quot2=[char]187; " ,
38793880 " `$ bullet=[char]8226; `$ arrow=[char]8594;" ,
38803881 " foreach(`$ inputItem in `$ inputCopy) {" ,
38813882 " `$ theItemTitle = If (`$ null -eq `$ itemTitle) { `"`$ inputItem`" } Else { ForEach-Object -InputObject `$ inputItem -Process `$ itemTitle | Select -First 1 };" ,
3883+ " `$ itemStartAt = [System.Diagnostics.Stopwatch]::StartNew()" ,
38823884 " `$ index++;" ,
38833885 " `$ textCounter = `"`$ index of `$ (`$ inputCopy.Length)`" " ,
38843886 " Write-Host `"`$ ([Environment]::NewLine)STARTING `$ (`$ textCounter): `$ (`$ actionTitle) for `$ (`$ quot1)`$ (`$ theItemTitle)`$ (`$ quot2)`" -ForeGroundColor Yellow" ,
@@ -3893,6 +3895,7 @@ $ModuleFiles = @(
38933895 " }" ,
38943896 " `$ isOk = `$ true;" ,
38953897 " `$ successNames += `$ theItemTitle" ,
3898+ " `$ successDetails += [PSCustomObject] @{ Title = `$ theItemTitle; Milliseconds = (`$ itemStartAt.ElapsedMilliseconds)};" ,
38963899 " }" ,
38973900 " catch {" ,
38983901 " `$ itemError = `$ _.Exception.Message;" ,
@@ -3905,13 +3908,13 @@ $ModuleFiles = @(
39053908 " Write-Host `" Error On: `$ inputItem`" " ,
39063909 " `$ isOk = `$ false;" ,
39073910 " `$ totalErrors++;" ,
3908- " `$ failDetails += [PSCustomObject] @{ Title = `$ theItemTitle; Error = `$ itemError};" ,
3911+ " `$ failDetails += [PSCustomObject] @{ Title = `$ theItemTitle; Error = `$ itemError; Milliseconds = ( `$ itemStartAt.ElapsedMilliseconds) };" ,
39093912 " }" ,
39103913 " " ,
39113914 " `$ eta = (`$ startAt.Elapsed.TotalSeconds / `$ index * `$ inputCopy.Length) - `$ startAt.Elapsed.TotalSeconds;" ,
39123915 " `$ color = If (`$ isOk) { `" Green`" } else { `" Red`" }" ,
39133916 " `$ status = If (`$ isOk) { `" Success`" } else { `" Fail`" }" ,
3914- " Write-Host `"`$ (`$ status): `$ textCounter `$ (`$ actionTitle) for `$ (`$ quot1)`$ (`$ theItemTitle)`$ (`$ quot2) (ETA: `$ (`" {0:n1}`" -f `$ eta)s)`" -ForeGroundColor `$ color" ,
3917+ " Write-Host `"`$ (`$ status): `$ textCounter `$ (`$ actionTitle) for `$ (`$ quot1)`$ (`$ theItemTitle)`$ (`$ quot2) (ETA: `$ (`" {0:n1}`" -f `$ eta)s, took `$ (Format-Milliseconds `$ itemStartAt.ElapsedMilliseconds) )`" -ForeGroundColor `$ color" ,
39153918 " if (`$ itemError) { Write-Host `" Error Message: `$ itemError`" -ForeGroundColor Red }" ,
39163919 " # Write-Host `" ETA: `$ (`" {0:n1}`" -f `$ eta)s`" " ,
39173920 " `$ host.ui.RawUI.WindowTitle = `" ETA: `$ (`" {0:n1}`" -f `$ eta)s. `$ textCounter. `$ (`$ quot1)`$ (`$ theItemTitle)`$ (`$ quot2)`" " ,
@@ -3923,24 +3926,34 @@ $ModuleFiles = @(
39233926 " Write-Host `" Total Finished: `$ (`$ inputCopy.Length); Failed: `$ totalErrors; Succeeded: `$ (`$ inputCopy.Length - `$ totalErrors); Duration: `$ ([Math]::Round(`$ startAt.Elapsed.TotalSeconds, 1))s`" " ,
39243927 " if (`$ successNames.Length -gt 0) {" ,
39253928 " Write-Host `"`$ actionTitle Success: `$ (`$ successNames.Length)`" " ,
3926- " foreach(`$ n in `$ successNames ) { Write-Host `" `$ bullet `$ (`$ quot1)`$ n `$ (`$ quot2)`" }" ,
3929+ " foreach(`$ n in `$ successDetails ) { Write-Host `" `$ bullet `$ (`$ quot1)`$ ( `$ n.Title) `$ (`$ quot2) ( `$ (Format-Milliseconds `$ n.Milliseconds) )`" }" ,
39273930 " } Else {" ,
39283931 " Write-Host `"`$ actionTitle Success: NONE`" " ,
39293932 " }" ,
39303933 " if (`$ failDetails.Length -gt 0) {" ,
3931- " Write-Host `"`$ actionTitle Fail: `$ (`$ failDetails.Length)`" " ,
3932- " foreach(`$ n in `$ failDetails) { Write-Host `" `$ bullet `$ (`$ quot1)`$ (`$ n.Title)`$ (`$ quot2) `$ arrow `$ (`$ n.Error)`" }" ,
3934+ " Write-Host `"`$ actionTitle Fail: `$ (`$ failDetails.Length)`" -ForegroundColor Red " ,
3935+ " foreach(`$ n in `$ failDetails) { Write-Host `" `$ bullet `$ (`$ quot1)`$ (`$ n.Title)`$ (`$ quot2) ( `$ (Format-Milliseconds `$ n.Milliseconds)) `$ arrow `$ (`$ n.Error)`" -ForegroundColor Red }" ,
39333936 " } Else {" ,
39343937 " Write-Host `"`$ actionTitle Fail: NONE`" " ,
39353938 " }" ,
39363939 " " ,
39373940 " `$ ret" ,
39383941 " }" ,
39393942 " " ,
3943+ " function Format-Milliseconds([long] `$ milliseconds) {" ,
3944+ " `$ date = ((new-object System.DateTime) + [System.Timespan]::FromMilliseconds(`$ milliseconds));" ,
3945+ " if (`$ milliseconds -le 9000) { return `" {0:0.0}s`" -f ([float] `$ milliseconds / [float]1000) }" ,
3946+ " elseif (`$ milliseconds -le (600000-1)) { return `" {0:HH:mm:ss}`" -f `$ date }" ,
3947+ " else { return `" {0:HH:mm:ss}`" -f `$ date }" ,
3948+ " }" ,
3949+ " " ,
3950+ " " ,
3951+ " " ,
39403952 " function Test-Try-Action-ForEach() {" ,
3953+ " `$ random = new-object System.Random(1); " ,
39413954 " `$ items = 1..7 | % { [PSCustomObject] @{ Key = `" Category `$ _`" } }" ,
39423955 " `$ itemTitle = { `"`$ (`$ _.Key)`" }" ,
3943- " `$ action = { Sleep 0.2 ; If (`$ _.Key -match `" 3`" ) { throw `"`$ (`$ _.Key) is not supported`" } }" ,
3956+ " `$ action = { Sleep -Milliseconds (200+150* `$ random.Next(2,5)) ; If (`$ _.Key -match `" 3`" ) { throw `"`$ (`$ _.Key) is not supported`" } }" ,
39443957 " `$ errors = @(`$ items | Try-Action-ForEach -ActionTitle `" Sleep`" -Action `$ action -ItemTitle `$ itemTitle)" ,
39453958 " Write-Host `"```$ errors.Length = `$ (`$ errors.Count)`" " ,
39463959 " Write-Host `$ errors" ,
0 commit comments