AKPT.psm1

<#
 
# AKPT-Module Import Script
 
Code der beim Laden/Entladen des Modules AKPT ausgeführt wird.
 
- **Hashtags** Module UserModule .PSM1
- **Version** 2020.12.22
 
#>

using namespace System.Management.Automation

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

Set-StrictMode -Version Latest

#region Public Cmdlets-Code ausführen

Get-ChildItem "$PSScriptRoot\Public\*.ps1" -PipelineVariable cmdlet |  ForEach-Object -Process {
    . $cmdlet.FullName
}

#endregion

#region Host-Prompt Anpassung

Get-Content -Path 'Function:\prompt' | New-Variable -Name 'promptBackup' -Scope 'Global' -Option 'ReadOnly' -Force
{
    $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

#endregion

#region Aufräumarbeiten bei Remove-Module -Name AKPT

$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 -ErrorAction 'Ignore'
    'alias:\gea', 'alias:\gbf', 'alias:\gee', 'alias:\gpi', 'alias:\gti' | Remove-Item -Force -ErrorAction 'Ignore'
 }

#endregion

Set-StrictMode -Off