繁体   English   中英

Psexec运行批处理文件没有错误,但没有任何效果

[英]Psexec runs batch file with no errors, but has no effect

我有一个批处理文件,该文件运行一个powershell脚本_1,该脚本以更高的凭据调用另一个powershell脚本_2。

当我登录remote_server(在WORKGROUP中为Win Server 2012 R2)并执行此批处理脚本时,它可以正常工作。

当我登录到host_server(在WORKGROUP中为Win Server 2012 R2)并使用psexec执行此批处理脚本时,返回的错误代码为0,但是当我测试该脚本是否有效时,就好像从未执行过powershell script_1或script_2一样

在host_server上,我将运行一个cmd shell,右键单击并选择“以其他用户身份运行”

在此处输入图片说明

然后为用户名输入“ Administrator”,然后输入密码。

然后我执行以下

D:\pstools\psexec.exe \\IP_of_remote_server -u username -p password -accepteula C:\share\enable.bat

并且它执行没有错误,并返回代码0

enable.bat

@echo off
powershell.exe C:\share\eLEVATE.ps1

eLEVATE.ps1

$startInfo = $NULL
$process = $NULL


<#Previously created password file in C:\share\cred.txt, read-host -assecurestring | convertfrom-securestring | out-file C:\share\cred.txt#>
$password = get-content C:\share\cred.txt | convertto-securestring

$startInfo = New-Object System.Diagnostics.ProcessStartInfo
$startInfo.FileName = "powershell.exe"
$startInfo.Arguments = "-noninteractive -windowstyle hidden -noprofile C:\share\remote_elevate.ps1 "

$startInfo.RedirectStandardOutput = $true
$startInfo.UseShellExecute = $false
$startInfo.CreateNoWindow = $false
$startInfo.Username = "Administrator"
$startInfo.Domain = "WORKGROUP"
$startInfo.Password = $password 

$process = New-Object System.Diagnostics.Process
$process.StartInfo = $startInfo
$process.Start() | Out-Null
$userId = $process.StandardOutput.ReadToEnd() 
$process.WaitForExit()

remote_elevate.ps1

enable-psremoting -force

我一直在努力解决这个问题。 谢谢!

编辑

我正在发布输入时得到的错误的确切屏幕截图

d:\\pstools\\psexec.exe \\\\remote_IP -u Administrator -p password -accepteula cmd

然后执行

powershell.exe -executionpolicy bypass c:\\share\\eLEVATE.ps1

在此处输入图片说明

我将其写为答案,因为注释不能传达有限格式所需要的内容。

在Host_server系统上,按照您的描述调出命令提示符。

输入以下命令:

d:\pstools\psexec.exe \\remote_IP -u username -p password -accepteula cmd

屏幕应该显示以下内容(由于我在Windows 7 Enterprise上运行此版本,因此Windows版本将有所不同,并且您将在Server 2012上执行此操作):

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>

现在,这是Remote_server上的命令提示符。 从此提示执行的任何操作都不会在本地(host_server)发生,但会在remote_server计算机上发生。 在此提示符下输入命令:

powershell.exe -executionpolicy bypass c:\share\eLEVATE.ps1

执行是否没有错误? 它能达到预期的效果吗?

完成测试并准备关闭remote_server系统上的命令提示符后,请使用以下命令:

exit

这将关闭远程命令提示符,并使您返回到本地计算机(host_server)上的命令提示符。

PSCM将声明返回码0,因为CMD.exe正常关闭。 这不反映PowerShell返回的任何内容,仅反映远程系统上的cmd.exe已正常执行并关闭。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM