Public/New-PsScript.ps1

function New-PsScript
{

  <#
    .Synopsis
      Short description
    .DESCRIPTION
      Long description
    .EXAMPLE
    Example of how to use this cmdlet
  #>


  [CmdletBinding(SupportsShouldProcess=$true)]  
  param (
    [Parameter(
        Mandatory=$true, 
        ValueFromPipeline=$true,
        ValueFromPipelineByPropertyName=$true)]
    [string]$ScriptName,
    [Alias("Path")]
    [string]$ScriptPath=""
  )  
    
  BEGIN{
    $path = (Get-Path $ScriptPath $PsScriptRoot)
  }#begin
  PROCESS{

    if ($psCmdlet.ShouldProcess($ScriptName, "Creating $path\$ScriptName.ps1")) { 
      
(@'
[CmdletBinding()]
param (
  [Parameter(Mandatory=$true,
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
  [ValidateSet("DEV", "STG", "PRD")]
  [string]$Environment,
  [Parameter(
      Mandatory=$true,
      ValueFromPipeline=$true,
      ValueFromPipelineByPropertyName=$true)]
  [ValidateScript({Test-Path $_ -PathType Any})]
  [string]$Path
)
 
<#
  .Synopsis
    Short description
  .DESCRIPTION
    Long description
  .EXAMPLE
    Example of how to use this cmdlet
#>
   
Write-Debug "Starting xxScriptNamexx..."
 
# stuff here...
 
Write-Debug "Finshed xxScriptNamexx..."
 
'@
).Replace("xxScriptNamexx", "$($ScriptName).ps1") | Set-Content "$path\$ScriptName.ps1" -Force
      
    }

  }#process
  END{

  }#end
}

function Get-Path {
  param(
    [string]$ScriptPath,
    [string]$Here
  )

  if ([string]::IsNullOrEmpty($ScriptPath)) {
    return $Here
  }

  if (!(Test-Path $ScriptPath -PathType Container)) {
    throw "The path provided is invalid... $ScriptPath"
  }

  return $ScriptPath
}