psexec命令
时间: 2023-06-29 17:20:06 浏览: 106
psexec是一款用于在远程计算机上执行命令的实用工具。它是Sysinternals工具包中的一员,现在已被Microsoft收购。使用psexec,管理员可以轻松地在远程计算机上运行命令行工具,如ipconfig、netstat、regedit等等。psexec命令的语法如下:
```
psexec \\remote_computer command
```
其中,remote_computer表示远程计算机的名称或IP地址,command表示要在远程计算机上执行的命令。psexec还支持一些其他的参数和选项,如-s(以系统账户的身份运行命令)、-d(在后台模式下运行命令)等等。
相关问题
帮我写一个cmd脚本,读取txt文件中的每一行主机名,并使用psexec命令:批量推送一个powershell文件到每一台主机中并运行这个文件,返回运行结果
当然,我可以帮你写一个 CMD 脚本来实现这个功能。以下是一个示例脚本:
```batch
@echo off
setlocal enabledelayedexpansion
set "txtfile=hosts.txt"
set "psfile=script.ps1"
set "outputfile=output.txt"
if not exist "!txtfile!" (
echo 文件 "!txtfile!" 不存在!
exit /b
)
if not exist "!psfile!" (
echo 文件 "!psfile!" 不存在!
exit /b
)
for /f "usebackq delims=" %%a in ("!txtfile!") do (
echo 处理主机: %%a
psexec \\%%a powershell -ExecutionPolicy Bypass -File "!psfile!" >> "!outputfile!" 2>&1
if errorlevel 1 (
echo 运行失败
) else (
echo 运行成功
)
)
echo 完成!请查看 "!outputfile!"
```
请将上述代码保存为一个 `.cmd` 文件,并将 `hosts.txt`、`script.ps1` 文件与脚本文件放在同一个目录下。
你需要将要连接的主机名逐行写入 `hosts.txt` 文件中,将要推送和运行的 PowerShell 脚本保存为 `script.ps1` 文件。
脚本会使用 `psexec` 命令来远程推送和运行 PowerShell 脚本,并将运行结果输出到 `output.txt` 文件中。
请注意,你需要确保 `psexec` 命令在系统的 PATH 路径中,否则你需要提供 `
psexec
PsExec是Sysinternals Suite中的一款命令行实用程序,它允许用户在远程计算机上运行命令和进程。通过PsExec,用户可以在远程计算机上运行命令提示符、PowerShell、Windows管理工具、Windows服务等。
以下是使用PsExec的基本步骤:
1. 下载Sysinternals Suite并解压缩。
2. 打开命令提示符并导航到解压缩后的Sysinternals Suite目录。
3. 使用以下命令格式来启动PsExec:
```
psexec \\RemoteComputer Command
```
其中,RemoteComputer是远程计算机的名称或IP地址,Command是要在远程计算机上执行的命令。
4. 例如,要在远程计算机上打开计算器,使用以下命令:
```
psexec \\RemoteComputer calc
```
这将在远程计算机上启动计算器。
需要注意的是,使用PsExec需要管理员权限,并且防火墙可能会阻止PsExec的使用。另外,使用PsExec进行远程访问时请注意安全问题,并确保您有权访问远程计算机。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)