工作正常動作功能執行,但PowerShell控制檯問題控制檯我得到:與在PowerShell ISE中註冊,ObjectEvent
術語「MainAction未被識別爲cmdlet的名稱, 功能,腳本文件或可操作的程序。檢查 名稱的拼寫,或者如果包含路徑,請驗證路徑是否正確,然後再次嘗試 。
如何解決?
function MainAction() {
$test = "123"
Write-Host $test
}
MainAction
$action = {
try {
Write-Host in action
MainAction
} catch {
Write-Host $Error
$timer.Stop()
Unregister-Event thetimer
}
}
$timer = New-Object Timers.Timer
Register-ObjectEvent -InputObject $timer -EventName elapsed `
-SourceIdentifier thetimer -Action $action -OutVariable out
$timer.Interval = 5000
$timer.AutoReset = $true
$timer.Start()
編輯:
我發現我可以用文件來存儲函數的定義。要create profile使用:
New-Item -path $profile -itemType file -force
但我'仍然intrested爲什麼PowerShell ISE中不需要的個人資料存儲和使用功能的Register-ObjectEvent
行動。
'函數MainAction' - >'函數全球: MainAction' – PetSerAl
你的權利,這個工作比輪廓更加方便易,謝謝 – Lavandil