====== Grundgerüst Powershellfunktion ====== ===== Typischer Aufbau eines Powershell-Cmdlets ===== function Test-Blubb { [CmdletBinding()] param ( #Insert Parameter-Definition here ) begin { #Insert actions here for initial setup of Cmdlet } process { #Insert here the recurring part for all transmitted objects } end { #Insert here final actions, like closing connections, dispose objects, etc... } } ===== CmdletBinding() ===== * Ermöglicht die erweiterte Bindung von Parametern im Scriptcode. Details [[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-5.1|hier]] * Die Funktion wird um die Möglichkeit ergänzt, den Verbose und Debug-Channel mitzunutzen (Write-Verbose, Write-Debug). Aktiviert wird die Nutzung im Aufruf dann mit den Parametern "-Debug" und "-Verbose" * Die Funktion wird um die Standardparameter ergänzt. Details [[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-5.1|hier]] * Mann kann die Parameter "-Confirm" und "-WhatIf" nutzen, müssen jedoch im Script berücksichtigt werden (([CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact=Medium)]))((Im Script muss die Abfrage mit Hilfe von $pscmdlet.ShouldProcess() implementiert werden)) Quelle: [[http://windowsitpro.com/blog/what-does-powershells-cmdletbinding-do|Link]] ===== Param-Block ===== [[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-5.1]]