![](/img/trans.png)
[英]How to create a local windows user account using remote powershell?
[英]windows run script with local user account from administrator powershell
我已經編寫了一個腳本,該腳本將對我的應用程序以及以本地用戶app1user
運行的應用程序進行一些app1user
。 因此,我需要從管理員帳戶運行該腳本,並使用runas /user:app1user
調用該腳本,但是它會提示輸入用戶app1user
密碼。
無論如何,我們可以克服這個問題並以app1user
運行該腳本,而無需通過powershell使用密碼。
也試圖僅從Evlevated powershell窗口調用該腳本。
在powershell中,可以使用-Verb RunAs 。 現在,您還可以從cmd中使用它,也可以直接從Powershell中使用它。
CMD:
powershell -Command "Start-Process powershell \"-ExecutionPolicy Bypass -NoExit -Command `\"cd \`\"C:\Temp\`\"; & \`\".\Script.ps1\`\"`\"\" -Verb RunAs"
具有新會話的Powershell(您也可以通過NoNewWindow ):
Start-Process powershell "-ExecutionPolicy Bypass -NoExit -Command `"cd \`"C:\Temp\`"; & \`".\Script.ps1\`"`"" -Verb RunAs
下一個替代方法是使用Dot Net:
# Get the ID and security principal of the current user account
$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent();
$myWindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($myWindowsID);
# Get the security principal for the administrator role
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator;
# Check to see if we are currently running as an administrator
if ($myWindowsPrincipal.IsInRole($adminRole)){"Its in elevated mode"}
希望這可以幫助...!!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.