I have found that users complain that some of my advanced functions appear to do nothing when run. I wrote the following bit to prompt them how to dot source a script:
If (($args.Count -eq 0) -and (!($ScriptVar))) {
$ScriptName = $MyInvocation.MyCommand.Name.Replace(".ps1","")
$commandline = $MyInvocation.InvocationName.trim()
if ($commandLine -ne "."){
$myFile = $MyInvocation.MyCommand.Definition.ToString()
Write-warning "This script requires arguments!"
write-host "You may put them at the end of the file or dot source with this with:
`n . `"$myFile`"`n`nfollowed by the command:`n`n$scriptName"
}Else{
Write-Host "Now run the command:`n`n$ScriptName`n`nYou can also run:`n`nGet-Help $ScriptName"
}
}
Put it at the bottom of your advanced function and replace $ScriptVar with a variable defined in your function. The code will prompt the user how to dot source the function.