【发布时间】:2016-05-08 19:48:14
【问题描述】:
我一直在做很多研究,但找不到一种方法来获取一个 powershell 脚本来查看主机文件,然后转到每个主机名并提取日志并将它们保存在一个地方,我有一个脚本正在运行这将提取日志,但仅在本地主机上。我该怎么做才能让脚本转到每台机器并执行我的脚本?
这就是它的牛肉我还有其他步骤将它放入文件只是想知道我如何使用您提到的命令跳转到每台机器并收集这些文件。
$computers = get-content C:\MyScripts\MachineNames.txt
foreach ($computer in $computers)
{
$Date = [DateTime]::Now.AddDays(-7)
$Date.tostring("MM-dd-yyyy"), $env:Computername
Get-EventLog "Security" -After $Date
| Where -FilterScript {$_.EventID -eq 4624 -and $_.ReplacementStrings[4].Length -gt 10 -and $_.ReplacementStrings[5] -notlike "*$"} `
| foreach-Object
$row = "" | Select UserName, LoginTime
$row.UserName = $_.ReplacementStrings[5]
$row.LoginTime = $_.TimeGenerated
$row # this will put the current row to the pipeline
} | Export-Csv 'c:\output.csv
现在我得到:在 line:9 char:1 + |其中 -FilterScript {$.EventID -eq 4624 -and $.ReplacementStrings[4].Length ... + ~ 不允许使用空的管道元素。 在行:15 字符:3 + } |导出-CSV 'c:\output.csv + ~ 不允许使用空的管道元素。 在行:15 字符:16 + } |导出-CSV 'c:\output.csv + ~~~~~~~~~~~~~~ 该字符串缺少终止符:'。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : EmptyPipeElement
【问题讨论】:
标签: powershell scripting