我想知道如何使用Invoke-Command傳遞參數以在腳本內使用以遠程運行。參數不會與Invoke-Command遠程使用,-computername返回null
enter code here
Param(
[string]$cname = (Read-Host "Computer Name?") ,
[string]$event = (Read-Host "What event?") ,
[string]$eventfilter = (Read-Host "What key word are you looking for?") '
[string]$amount = (Read-Host "How many events do you want to see?")
)
Invoke-Command -cn $cname -ScriptBlock {Get-EventLog -cn $cname -LogName $event -Message "*$eventfilter*" -Newest $amount | FT -Wrap}
我想知道這是否可能,我需要做什麼來修復這個腳本? 感謝
做一些研究似乎我需要使用的參數通過調用命令cmdlet來傳遞變量。仍試圖找出那部分。 – vnavna
Param( [string] $ cname ='讀取主機計算機名?', [string] $ event ='讀取主機什麼事件?', [string] $ eventfilter ='讀取主機什麼關鍵字是', [string] $ amount ='Read-Host你想看多少事件?' )Invoke-Command -ScriptBlock {Get-EventLog -cn $ cname -LogName $ event -Message * $ eventfilter *「| FT -Wrap} – vnavna