通过具有特权提升的批处理文件运行Powershell脚本 [英] Run Powershell script via batch file with elevated privileges

查看:84
本文介绍了通过具有特权提升的批处理文件运行Powershell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要运行Powershell脚本以通过批处理文件创建AD用户.问题是我需要以提升的特权(域管理员帐户)运行此PS脚本.我试图编写一个脚本".bat",其中包含所有这些信息,但到目前为止我一直没有成功.这是脚本:

I need to run a Powershell script to create AD user via a batch file. The thing is I need to run this PS script with elevated privileges (domain admin account). I have tried to script a '.bat' file which encloses all this information but I have been unsuccessful so far. Here is the script :

echo off
cls
echo Sign in with your ADM ID
set /p username=

powershell -noprofile -command "&{ start-process powershell -ArgumentList '-
noprofile -file C:\Users\...\Desktop\Powershell_scripts\New-ADuser\New-
Aduser_test.ps1' -verb RunAs}"

我已经尝试使用/netonly/user:adm @ domain行,但是它行不通.

I have tried with line /netonly /user:adm@domain but It won't work.

你们有什么主意吗?

谢谢.

推荐答案

我终于结束了:

runas.exe /netonly /noprofile /user:domainadm@domain "powershell.exe -
noprofile -File "C:\Users\...\Desktop\Powershell_scripts\New-
ADuser\.ps1" -verb RunAs"

它现在就像一种魅力!

希望它会帮助需要帮助的任何人. ;)

Hope it will help anyone in need. ;)

这篇关于通过具有特权提升的批处理文件运行Powershell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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