Script directory for a PowerShell profile. https://blog.lksz.me/keeping-track-of-everything/#-mypsscriptroot
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

52 linhas
1.3 KiB

  1. [CmdletBinding(SupportsShouldProcess)]param(
  2. [ArgumentCompleter({ param (
  3. $commandName,
  4. $parameterName,
  5. $wordToComplete,
  6. $commandAst,
  7. $fakeBoundParameters
  8. )
  9. [FunctionName]::_GetValidValues($wordToComplete,$true)
  10. })]
  11. [string[]]$ImportFunction,
  12. [switch]$ForceImport,
  13. [Parameter(Position = 0, ValueFromRemainingArguments = $true)]
  14. [ArgumentCompleter({ param (
  15. $commandName,
  16. $parameterName,
  17. $wordToComplete,
  18. $commandAst,
  19. $fakeBoundParameters
  20. )
  21. [MyScript]::_GetValidValues($wordToComplete,$false)
  22. })]
  23. [string[]]$ScriptName
  24. )
  25. $local:ScriptPaths = @()
  26. foreach( $local:p in $ImportFunction ) {
  27. $local:f = Get-Command $p -Type Function
  28. if( $f ) {
  29. $local:sp = Join-Path $MyPSScriptRoot "$p`.ps1"
  30. if( $ForceImport -or -not (Test-Path $sp) ) {
  31. Export-FunctionSource $p -NoHeader > $sp
  32. } elseif ( -not $ForceImport ) {
  33. throw "$p already exists in Script, to import the function again, use the -Force"
  34. }
  35. $ScriptPaths += $sp
  36. }
  37. }
  38. foreach( $local:p in $ScriptName ) {
  39. $local:sp = Join-Path $MyPSScriptRoot "$p`.ps1"
  40. $ScriptPaths += $sp
  41. }
  42. if( -not $ScriptPaths ) {
  43. $ScriptPaths += $MyPSScriptRoot
  44. }
  45. Edit-TextFile $ScriptPaths
  46. Get-Command Reload-MyScripts -ErrorAction SilentlyContinue |
  47. ForEach-Object { . $_.Definition }