首页 > 解决方案 > Windows Powershell 中的 runas /netonly 等价物是什么?

问题描述

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

标签: powershellactive-directorykerberospowershell-5.0

解决方案


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

例如:

启动过程

关于您要完成的工作,有几篇文章已经存在了一段时间。当然,这个查询之前已经出现过。

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

使用 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.

在 Powershell 中以其他用户身份运行命令

除了分类 Right click shift 之外,在 Powershell 中以不同用户身份运行命令的主要方法有三种。本文将向您展示如何在同一个 Powershell 会话中执行此操作。

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

也可以看看:

运行方式 1.3

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


推荐阅读