From b0cebeabe37ef9aaccf02bf95f35005c2b4cd88c Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Thu, 23 Mar 2017 10:17:40 -0600 Subject: [PATCH 1/3] Add command to get pertinent version info. --- .../PowerShellEditorServices.psd1 | 2 +- .../PowerShellEditorServices.psm1 | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/module/PowerShellEditorServices/PowerShellEditorServices.psd1 b/module/PowerShellEditorServices/PowerShellEditorServices.psd1 index 8354c6b42..681e06cb5 100644 --- a/module/PowerShellEditorServices/PowerShellEditorServices.psd1 +++ b/module/PowerShellEditorServices/PowerShellEditorServices.psd1 @@ -66,7 +66,7 @@ Copyright = '(c) 2016 Microsoft. All rights reserved.' # NestedModules = @() # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = @('Start-EditorServicesHost') +FunctionsToExport = @('Start-EditorServicesHost', 'Get-PowerShellEditorServicesVersion') # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @() diff --git a/module/PowerShellEditorServices/PowerShellEditorServices.psm1 b/module/PowerShellEditorServices/PowerShellEditorServices.psm1 index c2ee6cec7..4bfb00219 100644 --- a/module/PowerShellEditorServices/PowerShellEditorServices.psm1 +++ b/module/PowerShellEditorServices/PowerShellEditorServices.psm1 @@ -94,4 +94,33 @@ function Start-EditorServicesHost { } return $editorServicesHost -} \ No newline at end of file +} + +function Get-PowerShellEditorServicesVersion { + $nl = [System.Environment]::NewLine + + $versionInfo = "PSVersionTable:`n$($PSVersionTable | Out-String)" -replace '\n$', '' + + if ($IsLinux) { + $versionInfo += "Linux version: $(lsb_release -d)$nl" + } + elseif ($IsOSX) { + $versionInfo += "macOS version: $(lsb_release -d)$nl" + } + else { + $versionInfo += "Windows version: $(Get-CimInstance Win32_OperatingSystem | Foreach-Object Version)$nl" + } + + $versionInfo += $nl + + $OFS = ", " + $versionInfo += "VSCode version: $(code -v)$nl" + $OFS = "$nl " + $versionInfo += "VSCode extensions:$nl $(code --list-extensions --show-versions)" + + if (!$IsLinux -and !$IsOSX) { + $versionInfo | Microsoft.PowerShell.Management\Set-Clipboard + } + + $versionInfo +} From 32c580d1a92dd3b54b98641c3b4d610dd27c03fe Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Thu, 23 Mar 2017 20:13:00 -0600 Subject: [PATCH 2/3] Remove set-clipboard & code specific version info. --- .../PowerShellEditorServices.psm1 | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/module/PowerShellEditorServices/PowerShellEditorServices.psm1 b/module/PowerShellEditorServices/PowerShellEditorServices.psm1 index 4bfb00219..58f4be0df 100644 --- a/module/PowerShellEditorServices/PowerShellEditorServices.psm1 +++ b/module/PowerShellEditorServices/PowerShellEditorServices.psm1 @@ -99,27 +99,25 @@ function Start-EditorServicesHost { function Get-PowerShellEditorServicesVersion { $nl = [System.Environment]::NewLine - $versionInfo = "PSVersionTable:`n$($PSVersionTable | Out-String)" -replace '\n$', '' + $versionInfo = "PSES module version: $($MyInvocation.MyCommand.Module.Version)$nl" + $versionInfo += "PSVersion: $($PSVersionTable.PSVersion)$nl" + if ($PSVersionTable.PSEdition) { + $versionInfo += "PSEdition: $($PSVersionTable.PSEdition)$nl" + } + $versionInfo += "PSBuildVersion: $($PSVersionTable.BuildVersion)$nl" + $versionInfo += "CLRVersion: $($PSVersionTable.CLRVersion)$nl" + + $versionInfo += "Operating system: " if ($IsLinux) { - $versionInfo += "Linux version: $(lsb_release -d)$nl" + $versionInfo += "Linux $(lsb_release -d -s)$nl" } elseif ($IsOSX) { - $versionInfo += "macOS version: $(lsb_release -d)$nl" + $versionInfo += "macOS $(lsb_release -d -s)$nl" } else { - $versionInfo += "Windows version: $(Get-CimInstance Win32_OperatingSystem | Foreach-Object Version)$nl" - } - - $versionInfo += $nl - - $OFS = ", " - $versionInfo += "VSCode version: $(code -v)$nl" - $OFS = "$nl " - $versionInfo += "VSCode extensions:$nl $(code --list-extensions --show-versions)" - - if (!$IsLinux -and !$IsOSX) { - $versionInfo | Microsoft.PowerShell.Management\Set-Clipboard + $osInfo = Get-CimInstance Win32_OperatingSystem + $versionInfo += "Windows $($osInfo.OSArchitecture) $($osInfo.Version)$nl" } $versionInfo From 8ea28e171f114c59586761d0dbd6a11c2cda5e6e Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Thu, 23 Mar 2017 22:27:54 -0600 Subject: [PATCH 3/3] Add Compress-LogDir function. Overall, I don't like exposing such a "general purpose" command from the module. Maybe we have just one command called New-IssueReport that zips the folder and returns an object with the zipPath and version info? --- .../PowerShellEditorServices.psd1 | 2 +- .../PowerShellEditorServices.psm1 | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/module/PowerShellEditorServices/PowerShellEditorServices.psd1 b/module/PowerShellEditorServices/PowerShellEditorServices.psd1 index 681e06cb5..9911949ee 100644 --- a/module/PowerShellEditorServices/PowerShellEditorServices.psd1 +++ b/module/PowerShellEditorServices/PowerShellEditorServices.psd1 @@ -66,7 +66,7 @@ Copyright = '(c) 2016 Microsoft. All rights reserved.' # NestedModules = @() # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = @('Start-EditorServicesHost', 'Get-PowerShellEditorServicesVersion') + FunctionsToExport = @('Start-EditorServicesHost', 'Get-PowerShellEditorServicesVersion', 'Compress-LogDir') # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @() diff --git a/module/PowerShellEditorServices/PowerShellEditorServices.psm1 b/module/PowerShellEditorServices/PowerShellEditorServices.psm1 index 58f4be0df..5e4cbe35d 100644 --- a/module/PowerShellEditorServices/PowerShellEditorServices.psm1 +++ b/module/PowerShellEditorServices/PowerShellEditorServices.psm1 @@ -96,6 +96,50 @@ function Start-EditorServicesHost { return $editorServicesHost } +function Compress-LogDir { + [CmdletBinding(SupportsShouldProcess=$true)] + param ( + [Parameter(Mandatory=$true, Position=0, HelpMessage="Literal path to a log directory.")] + [ValidateNotNullOrEmpty()] + [string] + $Path + ) + + begin { + function LegacyZipFolder($Path, $ZipPath) { + if (!(Test-Path($ZipPath))) { + Set-Content -LiteralPath $ZipPath -Value ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) + (Get-Item $ZipPath).IsReadOnly = $false + } + + $shellApplication = New-Object -ComObject Shell.Application + $zipPackage = $shellApplication.NameSpace($ZipPath) + + foreach ($file in (Get-ChildItem -LiteralPath $Path)) { + $zipPackage.CopyHere($file.FullName) + Start-Sleep -MilliSeconds 500 + } + } + } + + end { + $zipPath = ((Convert-Path $Path) -replace '(\\|/)$','') + ".zip" + + if (Get-Command Microsoft.PowerShell.Archive\Compress-Archive) { + if ($PSCmdlet.ShouldProcess($zipPath, "Create ZIP")) { + Microsoft.PowerShell.Archive\Compress-Archive -LiteralPath $Path -DestinationPath $zipPath -Force -CompressionLevel Optimal + $zipPath + } + } + else { + if ($PSCmdlet.ShouldProcess($zipPath, "Create Legacy ZIP")) { + LegacyZipFolder $Path $zipPath + $zipPath + } + } + } +} + function Get-PowerShellEditorServicesVersion { $nl = [System.Environment]::NewLine