【发布时间】:2017-10-06 14:00:02
【问题描述】:
我想知道如何使用 Invoke-Command 传递参数以在远程运行的脚本中使用。
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}
我想知道这是否可行以及我需要做什么来修复这个脚本? 谢谢
【问题讨论】:
-
做一些研究似乎我需要使用参数通过 Invoke-Command cmdlet 传递变量。仍在试图弄清楚那部分。
-
Param( [string]$cname = 'Read-Host Computer Name?', [string]$event = 'Read-Host What event?', [string]$eventfilter = 'Read-Host你在找什么关键词?', [string]$amount = 'Read-Host 你想看多少个事件?' ) Invoke-Command -ScriptBlock {Get-EventLog -cn $cname -LogName $event -Message "$事件过滤器" | FT -Wrap}
标签: host invoke-command