JBOISES.psm1
<#
File: JBOISES.psm1 Author: Casper Stekelenburg Publisher: Casper Stekelenburg Copyright: © 2016 Casper Stekelenburg. All rights reserved. Usage: To load this module in PowerShell: Import-Module -Name JBOISES Notes: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #> If ($Host.Name -ne "Windows PowerShell ISE Host") { Write-Warning "The JBOISES module does only run inside PowerShell ISE" Break } Function Add-HeaderToScript { <# .Synopsis This function adds header information to a script .Example Add-HeaderToScript Adds header comments to script .Example AH Uses alias to add header comments to script .Notes NAME: Add-HeaderToScript AUTHOR: ed wilson, msft Modified by: Casper Stekelenburg LASTEDIT: $(Get-Date) KEYWORDS: $keyword HSG: $hsg .Link Http://www.ScriptingGuys.com #Requires -Version 2.0 #> Param($keyword, $comment, $hsg) $author=(Get-WmiObject win32_useraccount).FullName $header = @" # ----------------------------------------------------------------------------- # Script: $(split-path -Path $psISE.CurrentFile.FullPath -Leaf) # Author: $author # Date: $(Get-Date) # Keywords: $keyword # comments: $comment # # ----------------------------------------------------------------------------- "@ $psise.CurrentFile.Editor.InsertText($header) } Function Add-Help { <# .Synopsis This function adds help at current insertion point .Example add-help adds comment based help at current insertion point .Notes NAME: Add-Help AUTHOR: ed wilson, msft Modified by: Casper Stekelenburg LASTEDIT: 09/07/2010 17:32:34 HSG: WES-09-11-10 KEYWORDS: Scripting Techniques, Windows PowerShell ISE .Link Http://www.ScriptingGuys.com #Requires -Version 2.0 #> param( [string]$synopsis, [string]$description, [string]$inputs, [string]$outputs, [string]$name, [string]$externalhelp, [string]$forwardhelptargetname, [string]$keywords, [string]$functionality, [string]$dependencies = "Powershell v2" ) $author=(Get-WmiObject win32_useraccount).FullName $helpText = @" <# .Synopsis $synopsis .Description $description .Example Example Example accomplishes .Parameter parametername The parameter description .Inputs $inputs .Outputs $outputs .Author $author .Externalhelp $externalhelp .Forwardhelptargetname $forwardhelptargetname .Functionality $functionality .Keywords $keywords .Notes NAME: $name AUTHOR: $author LASTEDIT: $(Get-Date) KEYWORDS: $keywords .Dependencies $dependencies .LINK about_functions_advanced .LINK about_CommonParameters #> "@ $psise.CurrentFile.Editor.InsertText($helpText) } Function Add-BaseFunctionOption { #$modulename=$psISE.CurrentFile.DisplayName.Split(".")[0] $defaultfunctionstuff = @" [CmdletBinding( SupportsShouldProcess=$true, ConfirmImpact="Medium", DefaultParameterSetName="Default", SupportsShouldContinue=$true, SupportsPaging=$true, PositionalBinding=$false )] Param( [parameter( Mandatory=$true, ValueFromPipeline=$true, HelpMessage="This is a HelpMessage", ValueFromPipelineByPropertyName=$true, ParameterSetName="Default" )] $parameter ) "@ $psise.CurrentFile.Editor.InsertText($defaultfunctionstuff) } Function New-Function { [CmdletBinding( SupportsShouldProcess=$true, ConfirmImpact="Medium", DefaultParameterSetName="Default", PositionalBinding=$false )] Param() $functionstart= @" Function Change-Name { "@ $functionend= @" } "@ $psise.CurrentFile.Editor.InsertText($functionstart) Add-Help Add-BaseFunctionOptions $psise.CurrentFile.Editor.InsertText($functionend) } Function Add-CertificateSignature { <# .Synopsis Signs the current script file .Description Signs the file currently active in ISE. Saves the scriptfile with UTF8 encoding (standard ISE file encoding breaks the Set-AuthenticodeSignature command). .Example Add-CertificateSignature Signs the current script file .Inputs None .Outputs None .Notes NAME: Add-CertificateSignature AUTHOR: Casper Stekelenburg LASTEDIT: 04/24/2016 12:35:31 KEYWORDS: .LINK about_functions_advanced .LINK about_CommonParameters #> [CmdletBinding( SupportsShouldProcess=$true, ConfirmImpact="Medium" )] Param() $psISE.CurrentFile.Save([Text.Encoding]::UTF8) $acert=(ls Cert:\CurrentUser\My -CodeSigningCert)[0] Set-AuthenticodeSignature $psISE.CurrentFile.FullPath -Certificate $acert } # *** Alias *** If(!(Test-Path alias:ah)) { New-Alias -Name ah -Value add-headertoscript -Description "MrEd alias" | Out-Null } If(!(Test-Path alias:AHLP)) { Set-Alias -Name AHLP -Value add-help -Description "MrEd alias" | Out-Null } If(!(Test-Path alias:ABFO)) { Set-Alias -Name ABFO -Value Add-BaseFunctionOption -Description "Add basic function options" | Out-Null } If(!(Test-Path alias:NF)) { Set-Alias -Name NF -Value New-Function -Description "New function" | Out-Null } If(!(Test-Path alias:ACS)) { Set-Alias -Name ACS -Value Add-CertificateSignature -Description "Sign script files" | Out-Null } Export-ModuleMember -Alias * -Function * -Variable * -Cmdlet * |