AKPT.psm1

# ? TITEL AKPT
# ? DESCRIPTION Code der beim Laden/Entladen des Modules AKPT ausgeführt wird.
# ? TAGS Module UserModule .PSM1
# ? VERSION 2019.11.15

using Module Microsoft.PowerShell.Management
using Module Microsoft.PowerShell.Utility

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalFunctions', '')]
param()

Set-StrictMode -Version Latest

Get-Content -Path Function:\prompt | New-Variable -Name promptBackup -Scope Global -Option ReadOnly
{
    $lastCmd = Get-History -Count 1
    if ($null -ne $lastCmd) {
        $timeSpan = $lastCmd.EndExecutionTime - $lastCmd.StartExecutionTime
        "[ {0}h {1}m {2}s {3}ms ] {4}$('>' * ($nestedPromptLevel + 1)) " -f $timeSpan.Hours, $timeSpan.Minutes, $timeSpan.Seconds, $timeSpan.Milliseconds, $executionContext.SessionState.Path.CurrentLocation
        } else {
        "[ 0 ms ] $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "
    }
} | Set-Content -Path Function:\prompt

$code = {
    Add-Type -AssemblyName System.Windows.Forms

    $propertyGrid                = New-Object System.Windows.Forms.PropertyGrid
    $propertyGrid.Dock           = [System.Windows.Forms.DockStyle]::Fill
    $propertyGrid.PropertySort   = [System.Windows.Forms.PropertySort]::Alphabetical
    $propertyGrid.SelectedObject = $this

    $window         = New-Object System.Windows.Forms.Form
    $window.Text    = $this.ToString()
    $window.Size    = New-Object System.Drawing.Size -ArgumentList @(600, 800)
    $window.TopMost = $true
    $window.Controls.Add($propertyGrid)
    $window.ShowDialog() | Out-Null
}
Update-TypeData -MemberType ScriptMethod -MemberName ShowObject -Value $code -TypeName System.Object -Force
  
$code = {
    $url = 'https://docs.microsoft.com/de-de/dotnet/api/{0}' -f $this.GetType().FullName
    Start-Process $url
}
Update-TypeData -MemberType ScriptMethod -MemberName GetHelp -Value $code -TypeName System.Object -Force
  
Get-ChildItem "$PSScriptRoot\Cmdlets\*.ps1" -Exclude *.Tests.ps1 |  ForEach-Object {
    . $_.FullName
}

$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {

    Remove-TypeData -TypeName System.Object -ErrorAction Ignore

    $Global:promptBackup | Set-Content -Path Function:\prompt -Force
    Remove-Variable -Name promptBackup -Scope Global -Force

    "Modul AKPT wurde entladen." | Write-Warning
 }

 "Modul AKPT geladen." | Write-Warning