AptPackage.psm1
# Module created by Microsoft.PowerShell.Crescendo class PowerShellCustomFunctionAttribute : System.Attribute { [bool]$RequiresElevation [string]$Source PowerShellCustomFunctionAttribute() { $this.RequiresElevation = $false; $this.Source = "Microsoft.PowerShell.Crescendo" } PowerShellCustomFunctionAttribute([bool]$rElevation) { $this.RequiresElevation = $rElevation $this.Source = "Microsoft.PowerShell.Crescendo" } } function ConvertAptShow { [CmdletBinding()] param ( [Parameter(Mandatory = $true, Position = 1)] [Array]$NativeOutput ) # Join Description $description = ($NativeOutput | Where-Object { $_ -match "(^(Description\b))|^\s" } | ForEach-Object { $_.trim() }) -join " " # Trim orginial multiline Description [System.Collections.ArrayList]$trimContent = ($NativeOutput | Where-Object { $_ -notmatch "(^(Description\b))|^\s|^\B" }) # Add joined Description $trimContent.Add($description) # Construct output object $multiStr = $trimContent -join "`n" return [PSCustomObject]($multiStr -replace ": ", "=" | ConvertFrom-StringData) } function Show-AptPackage { [PowerShellCustomFunctionAttribute(RequiresElevation = $False)] [CmdletBinding()] param( [Parameter(Position = 1, Mandatory = $true, ParameterSetName = 'Default')] [string]$PackageName ) BEGIN { $__PARAMETERMAP = @{ PackageName = @{ OriginalName = '' OriginalPosition = '0' Position = '1' ParameterType = 'string' ApplyToExecutable = $False NoGap = $False } } $__outputHandlers = @{ Default = @{ StreamOutput = $False; Handler = 'ConvertAptShow' } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({ $_.Attributes.Where({ $_.TypeId.Name -eq "PSDefaultValueAttribute" }) }).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({ $__boundParameters["$_"] = get-variable -value $_ }) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({ $_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name] }).ForEach({ $__boundParameters[$_.Name] = [switch]::new($false) }) if ($__boundParameters["Debug"]) { wait-debugger } $__commandArgs += 'show' foreach ($paramName in $__boundParameters.Keys | Where-Object { !$__PARAMETERMAP[$_].ApplyToExecutable } | Sort-Object { $__PARAMETERMAP[$_].OriginalPosition }) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { $pFmt = "{0}{1}" if ($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } else { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } $__commandArgs += $value | Foreach-Object { $_ } } } } $__commandArgs = $__commandArgs | Where-Object { $_ -ne $null } if ($__boundParameters["Debug"]) { wait-debugger } if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message apt $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("apt $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "apt")) { throw "Cannot find executable 'apt'" } if ( $__handlerInfo.StreamOutput ) { & "apt" $__commandArgs | & $__handler } else { $result = & "apt" $__commandArgs & $__handler $result } } } # end PROCESS <# .DESCRIPTION Get Package Information .PARAMETER PackageName Specify the name of package to show #> } Export-ModuleMember Show-AptPackage |