powershell 启动admin powershell

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 启动admin powershell相关的知识,希望对你有一定的参考价值。

function Launch-Admin-Shell () {
    # 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 Administrator"
    if ($myWindowsPrincipal.IsInRole($adminRole))
    {
    # We are running "as Administrator" - so change the title and background color to indicate this
    $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
    $Host.UI.RawUI.BackgroundColor = "DarkBlue"
    clear-host
    }
    else
    {
    
    # Create a new process object that starts PowerShell
    $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
    
    # Specify the current script path and name as a parameter
    $newProcess.Arguments = $myInvocation.MyCommand.Definition;
    
    # Indicate that the process should be elevated
    $newProcess.Verb = "runas";

    # Loads the UserProfile into the subprocess
    $newProcess.LoadUserProfile = $true;
    
    # Start the new process
    [System.Diagnostics.Process]::Start($newProcess);
    
    # Exit from the current, unelevated, process
    exit
    }
}

以上是关于powershell 启动admin powershell的主要内容,如果未能解决你的问题,请参考以下文章

PowerShell ISE:调试从 power-shell 脚本调用的另一个 power-shell 脚本

Rubix - ReactJS Powered Admin Template 后台管理框架

如何在Windows Server 2008 R2上开启Windows Power Shell ISE

powershell 更新power shell中的帮助系统。第二个文件在Windows中显示帮助文件。第三个文件显示来自在线来源的帮助。

powershell 这将使用power shell获取特定SharePoint网站集下的所有子网站的列表。第二个文件获取我们的子站点

如何使用Windows Power Shell