如何在 PowerShell 中远程执行 ELEVTED 远程脚本 [英] How to remote execute an ELEVATED remote script in PowerShell

查看:74
本文介绍了如何在 PowerShell 中远程执行 ELEVTED 远程脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两台服务器:

  • serverA(Windows 2003 服务器)
  • serverB(Windows 7)
  • serverA (windows 2003 server)
  • serverB (windows 7)

ServerA 包含一个文件夹,其中包含一个批处理文件 (deploy.bat),需要从提升的 powershell 提示符下执行.在 ServerA 中,如果我从普通提示或 powershell 提示运行它,它会失败.如果我从提升的提示运行它,它就可以工作.(以管理员身份运行).

ServerA contains a folder with a batch file (deploy.bat) that needs to be executed from an elevated powershell prompt. In ServerA, if I run it from a normal prompt or powershell prompt it fails. If I run it from an elevated prompt it works. (run as administrator).

我遇到的问题是当我尝试使用远程 powershell 执行从 serverB 执行批处理文件时.我可以用这个命令执行:

The problem I have is when I try to execute batch file from serverB using a remote powershell execution. I am able to execute with this command:

Invoke-Command -computername serverA .\remotedeploy.ps1

remotedeploy.ps1 的内容是:

cd D:\Builds\build5
.\Deploy.bat

我在 stackoverflow 中看了很多关于以下内容的问题:

I have looked a lot questions in stackoverflow about:

  • 执行远程 powershell(这对我有用)
  • 使用提升的提示执行本地 powershell(我可以做到)

这个问题是关于两者的.所以确切的问题是:

This question is about both at the same time. So the exact question is:

是否可以在 PowerShell 中执行 ELEVATED REMOTE 脚本?

推荐答案

您是否尝试将 remoteDeploy.ps1 更改为以提升的权限启动 CMD.EXE :

Do you try to change remoteDeploy.ps1 to start CMD.EXE with elevated rights :

cd D:\Builds\build5
start-process CMD.EXE -verb runas -argumentlist "-C",".\Deploy.bat"

这篇关于如何在 PowerShell 中远程执行 ELEVTED 远程脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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