Public/Stop-Psm.ps1

function Stop-Psm {
  <#
    .Synopsis
      Stop-Psm removes all of the public and internal functions from the current session
    .DESCRIPTION
      Stop-Psm removes all of the public and internal functions from the current session
    .EXAMPLE
      Stop-Psm
  #>
      
  [CmdletBinding(SupportsShouldProcess=$true)]  
  param (
    [string]$scriptBlock=""
  )  

  BEGIN{
    Write-Verbose "Starting Stop-Psm..."
    Confirm-IsInitializedModulePath
    $psd1 = Import-Clixml .\module-psd1.xml
    $folderPath = "Module-Stop"
  }#begin

  PROCESS{
    if ($psCmdlet.ShouldProcess(<# on target --> #>"Module Name", <# What if: Performing operation --> #>"Removing all public and internal functions from the PS session")) { 
      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) {

            Write-Verbose -Message " Importing $($script.BaseName)"
            . $($script.FullName) -Verbose
            
          }
        } else {
          Write-Error "Please pass a script block as a string to 'Stop-Psm' or create scripts in the $folderPath/ directory"
        }
      }
      
      Write-Verbose "Removing module..."
      Remove-Module $psd1.ModuleName -Verbose
    }
  }#process
  END{
    Write-Verbose "Finished Stop-Psm..."
  }#end
}