如何插入断开或键序列信息powershell作业
我正在尝试在一系列机器上运行netmon,我能够启动netmon,这看起来很好。但是,当我发出如何插入断开或键序列信息powershell作业,powershell,powershell-2.0,powershell-3.0,netmon,Powershell,Powershell 2.0,Powershell 3.0,Netmon,我正在尝试在一系列机器上运行netmon,我能够启动netmon,这看起来很好。但是,当我发出停止作业*时,netmon似乎没有正确关闭,这导致数据包捕获无效。Netmon希望出现“ctrl+C”,当我停止作业时,有没有办法发出此消息?Netmon可以使用/stopwhen/keypress选项使用其他按键序列 $server = get-content C:\Server.txt $capturedevice = "CAPTUREMACHINE" foreach ($server in $
停止作业*
时,netmon似乎没有正确关闭,这导致数据包捕获无效。Netmon希望出现“ctrl+C”,当我停止作业时,有没有办法发出此消息?Netmon可以使用/stopwhen/keypress选项使用其他按键序列
$server = get-content C:\Server.txt
$capturedevice = "CAPTUREMACHINE"
foreach ($server in $server)
{ $scriptBlockContent = { param ($servername)
Nmcap /capture /network * /file C:\temp\"$servername".chn:400MB }
Invoke-Command -ComputerName $server -Scriptblock $scriptBlockContent -ArgumentList $server -AsJob }
foreach ($capturedevice in $capturedevice){ $scriptBlockContent =
{ param ($capturedevicename) Nmcap /capture /network * /file D:\temp\"$capturedevicename".chn:400MB }
Invoke-Command -ComputerName $capturedevice -Scriptblock $scriptBlockContent -ArgumentList $capturedevice -AsJob }
我没有现成的解决方案给你,但这里有一些值得思考的东西 您有两个问题需要解决:
Nmcap
进程,以便它可以保存捕获文件
启动流程
:
$nmcap = Start-Process -FilePath "Nmcap" -ArgumentList "/capture /network * /file C:\temp\"$servername".chn:400MB"
$nmcap.Close() #or $nmcap.CloseMainWindow()
$nmcap.WaitForExit()
$nmcap.Close()
或$nmcap.CloseMainWindow()
上述代码无法工作,则您可以尝试将Ctrl+C发送到nmcap
:
$Wasp = Add-Type -MemberDefinition @'
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
'@ -Passthru
$null = Add-Type -Assembly System.Windows.Forms
if($Wasp::SetForegroundWindow($nmcap.MainWindowHandle)) {
[System.Windows.Forms.SendKeys]::SendWait("^C")
$nmcap.WaitForExit()
}
Nmcap
进程,您必须在PowerShell尝试停止此作业时检测作业内部
谢谢,我来试一试。