使用 psexec 发送多个命令 [英] Sending multiple commands with psexec

查看:37
本文介绍了使用 psexec 发送多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想压缩

psexec \\server taskill /f /t /fi "USERNAME eq $username" /im soffice*
psexec \\server taskill /f /t /fi "USERNAME eq $username" /im swriter*
psexec \\server taskill /f /t /fi "USERNAME eq $username" /im scalc*
psexec \\server taskill /f /t /fi "USERNAME eq $username" /im simpress*

变成一个 psexec 命令.通常我会尝试 & 操作符来做 so &所以 但由于我是在 PS 中做这一切,它似乎并不喜欢那样.我尝试了一组 ()"" 但它似乎也不喜欢那些.

Into one psexec command. Normally I'd try the & operator to do so & so but since I'm doing this all in PS, it doesn't seem to like that. I tried an array of () and "" but it doesn't seem to like those either.

最终只是复制了一个 .cmd (BAT) 文件并在我的 $PROFILE 本地创建了一个快捷方式.

Ended up just copying a .cmd (BAT) file and making a shortcut in my $PROFILE locally.

function flushlibra
{
param([string]$user = "")
if ($user -eq "")
{
    $user = Read-Host "User to nuke LibraOffice proccesses: "
}

psexec -c "\\unc\path\to\flushlibra.cmd" $user
}

.cmd 文件

taskkill /f /t /fi "USERNAME eq %1" /im soffice*
taskkill /f /t /fi "USERNAME eq %1" /im swriter*
taskkill /f /t /fi "USERNAME eq %1" /im scalc*
taskkill /f /t /fi "USERNAME eq %1" /im simpress*

推荐答案

psexec 还允许您远程调用批处理脚本,而不仅仅是单个命令.使用 -c 开关指示应将脚本复制到远程系统.

psexec allows you to invoke a batch script remotely, too, not just single commands. Use the -c switch to indicate that the script should be copied to the remote system.

所以如果你本地有一个脚本 KillProcs.cmd:

So if you locally have a script KillProcs.cmd:

taskill /f /t /fi "USERNAME eq $username" /im soffice*
taskill /f /t /fi "USERNAME eq $username" /im swriter*
taskill /f /t /fi "USERNAME eq $username" /im scalc*
taskill /f /t /fi "USERNAME eq $username" /im simpress*

然后你可以像这样远程运行

Then you can run that remotely like this

psexec \\server -c c:\localpath\KillProcs.cmd

这篇关于使用 psexec 发送多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆