diff --git a/module/PowerShellEditorServices/PowerShellEditorServices.psd1 b/module/PowerShellEditorServices/PowerShellEditorServices.psd1 index 8354c6b42..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') + 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 c2ee6cec7..5e4cbe35d 100644 --- a/module/PowerShellEditorServices/PowerShellEditorServices.psm1 +++ b/module/PowerShellEditorServices/PowerShellEditorServices.psm1 @@ -94,4 +94,75 @@ function Start-EditorServicesHost { } return $editorServicesHost -} \ No newline at end of file +} + +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 + + $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 $(lsb_release -d -s)$nl" + } + elseif ($IsOSX) { + $versionInfo += "macOS $(lsb_release -d -s)$nl" + } + else { + $osInfo = Get-CimInstance Win32_OperatingSystem + $versionInfo += "Windows $($osInfo.OSArchitecture) $($osInfo.Version)$nl" + } + + $versionInfo +}