Windows Powershell 中 runas /netonly 的等效项是什么?

lee*_*d00 6 powershell kerberos active-directory powershell-5.0

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

pos*_*ote 2

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

例如:

启动进程

有几篇关于您想要实现的目标的文章已经流传了一段时间。当然,这个问题之前已经出现过。

RunAS /netony - PowerShell 等效项?

# 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
Run Code Online (Sandbox Code Playgroud)

使用 PowerShell 脚本以不同用户身份运行并提升进程。

# 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 Code Online (Sandbox Code Playgroud)

在 Powershell 中以不同用户身份运行命令

除了右键单击 Shift 之外,在 Powershell 中以不同用户身份运行命令的主要方式还有三种。本文将向您展示如何在同一 Powershell 会话中执行此操作。

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

也可以看看:

运行方式 1.3

Windows“runas”命令的一个版本,它接受 PSCredential 而不是提示输入密码。

  • OP 特别询问了“runas”的“/netonly”参数。“/netonly”的工作方式是在执行“runas”时接收凭据。但是,这些凭据目前尚未经过验证。相反,它们仅在“runas”启动的程序尝试访问网络时应用。这与添加“-Credential”参数时“Start-Process”等 cmdlet 执行的操作不同。在这种情况下,将立即评估凭据。这可能会导致身份验证失败,并且此错误可能会阻止进程启动。 (3认同)