Public/Start-Psm.ps1
function Start-Psm { <# .Synopsis Start-Psm imports all of the public and internal functions into the current session .DESCRIPTION Start-Psm imports all of the public and internal functions into the current session .EXAMPLE Start-Psm #> [CmdletBinding(SupportsShouldProcess=$true)] param ( [string]$scriptBlock="" ) BEGIN{ Write-Verbose "Starting Start-Psm..." Confirm-IsInitializedModulePath $psd1 = Import-Clixml .\module-psd1.xml $folderPath = "Module-Start" }#begin PROCESS{ if ($psCmdlet.ShouldProcess(<# on target --> #>"Module Name", <# What if: Performing operation --> #>"Importing all public and internal functions into the PS session")) { Write-Verbose "Importing module .\$($psd1.RootModule)..." Import-Module ".\$($psd1.RootModule)" -Verbose if ($scriptBlock) { Write-Verbose "Running script block" & ([scriptblock]::Create($scriptBlock)) } else { If (Test-Path -Path $folderPath -PathType Container) { Write-Verbose -Message "Importing from $folder" $scripts = Get-ChildItem -Path $folderPath -Filter "*.ps1" ForEach ($script in $scripts) { if ($script.BaseName -match "tests") { continue } Write-Verbose -Message " Importing $($script.BaseName)" . $($script.FullName) -Verbose } } else { Write-Error "Please pass a script block as a string to 'Start-Psm' or create scripts in the $folderPath/ directory" } } } }#process END{ Write-Verbose "Finished Start-Psm..." }#end } |