AKPT.psm1
# ? TITEL AKPT-Module Import Script # ? DESCRIPTION Code der beim Laden/Entladen des Modules AKPT ausgeführt wird. # ? TAGS Module UserModule .PSM1 # ? VERSION 2020.01.14 #region Prolog [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalFunctions', '')] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')] param() Set-StrictMode -Version Latest #endregion #region Variablen-Management # ! Wird für das Cmdlet Find-Know benötigt New-Variable -Name AkptModulePath -Value $PSScriptRoot -Option ReadOnly -Visibility Public -Force -Scope Global #endregion #region Public Cmdlets-Code ausführen Get-ChildItem "$PSScriptRoot\Public\*.ps1" | ForEach-Object { . $_.FullName } #endregion #region Host-Prompt Anpassungen 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 Typen-Erweiterungen $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 #endregion #region Aufräumarbeiten $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 Remove-Variable -Name AkptModulePath -Scope Global -Force -ErrorAction Ignore } #endregion #region Epilog & "$AkptModulePath\Private\Scripts\TipOfTheDay.ps1" #endregion |