代码之家  ›  专栏  ›  技术社区  ›  leeand00

在Windows Powershell中,runas/netonly的等价物是什么?

  •  0
  • leeand00  · 技术社区  · 5 年前

    是否可以从Powershell启动一个程序,使用不同的Kerberos令牌进行网络访问,就像您使用 runas /netonly

    0 回复  |  直到 5 年前
        1
  •  3
  •   postanote    5 年前

    当您使用具有RunAs选项的cmdlet时,PowerShell确实具有RunAs选项。

    例如:

    Start-Process

    RunAS /netony - PowerShell equivalent ?

    # You can't use 'runas' directly in Powershell.  Anyway as you know, Runas will prompt for a password. 
    
    # To run a program with different credentials in Powershell is a two-part process:
    
    # 1. Store the password interactively to an encoded text file:
    
    
    $credential = Get-Credential 'targetDomain\user'
    $credential.Password | ConvertFrom-SecureString | Set-Content c:\scripts\password.txt
    

    Using a PowerShell script to run as a different user & elevate the process.

    # The script:
    
    Start-Process powershell.exe -Credential "TestDomain\Me" -NoNewWindow -ArgumentList "Start-Process powershell.exe -Verb runAs"
    
    <#
    The following section starts the PowerShell command-line process with Start-Process 
    prompting for user credentials. You may not need this dependent on UAC settings, 
    as you might already get an over-the-shoulder prompt for creds during elevation. 
    #> 
    
    Start-Process powershell.exe -Credential "TestDomain\Me"
    
    # The -NoNewWindow parameter re-uses the same PowerShell command window.
    

    Run a command as a different user in Powershell

    有三种主要方式可以作为不同的用户在中运行命令 Powershell,除了分类右键单击shift。本文将 演示如何在同一个Powershell会话中执行此操作。

    这里有一个脚本可以根据需要下载和剖析。

    另请参见:

    RunAs 1.3

    接受