How to import a new powershell cmdlet?

I just downloaded the cmdlet Register-TemporaryEventfrom http://poshcode.org/2205 and placed it in my powershell profile directory next to the $profilescript.

How to create a new team Register-TemporaryEventthat will be attached to this script?

Thank.

+5
source share
2 answers

With PowerShell, you can execute scripts as commands if they are placed in the directories contained in the PATH environment variable. To find out which directories are in the Path, you can use:

$env:Path -split ';'| sort

" Windows", , script. , :

$ScriptRoot = Split-Path $SCRIPT:MyInvocation.MyCommand.Path

if(($env:Path -split ';') -notcontains $ScriptRoot) {
    $env:Path += ';' + $ScriptRoot
}

:

PS >$timer = New-Object Timers.Timer
PS >Register-TemporaryEvent $timer Disposed { [Console]::Beep(100,100) }

. , Register-TemporaryEvent.ps1, ".ps1", .

+2

script, .

$sb = Get-Content .\script.ps1 | Out-String
Invoke-Expression "function Register-TemporaryEvent {`n $sb `n} "
+2

All Articles