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 Typen-Erweiterungen

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

    $propertyGrid                            = New-Object -TypeName 'System.Windows.Forms.PropertyGrid'
    $propertyGrid.Dock                       = [System.Windows.Forms.DockStyle]::Fill
    $propertyGrid.PropertySort               = [System.Windows.Forms.PropertySort]::Alphabetical
    $propertyGrid.CanShowVisualStyleGlyphs   = $true
    $propertyGrid.CommandsVisibleIfAvailable = $true
    $propertyGrid.HelpVisible                = $true
    $propertyGrid.ToolbarVisible             = $true
    $propertyGrid.SelectedObject             = $this

    $window         = New-Object -TypeName 'System.Windows.Forms.Form'
    $window.Text    = $this.ToString()
    $window.Size    = New-Object -TypeName '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 
  
#endregion

#region Microsoft PowerShell News

' ' | Out-Host
'Microsoft PowerShell Blog 📰 News:' | Out-Host
[xml]$content = Invoke-WebRequest -Uri 'https://devblogs.microsoft.com/powershell/feed/' | Select-Object -ExpandProperty Content
$content.rss.channel.Item | Select-Object pubDate, title, link | ForEach-Object -Process {
    [PSCustomObject]@{
        Release = '📅 {0:yyyy-MM-dd}' -f ([DateTime]$_.pubDate)
        News    = @"
📯 $($_.Title)
🔗 $($_.link)
"@

    }
} | Format-Table -Wrap | Out-Host

#endregion





#region Tip od the Day

& (Join-Path -Path $PSScriptRoot -ChildPath "\Private\Scripts\TipOfTheDay.ps1")

#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' | Remove-Item -Force -ErrorAction 'Ignore'
 }

#endregion

Set-StrictMode -Off