You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地管理员组成员运行PowerShell修改用户密码脚本时遭遇访问被拒的问题求助

本地管理员组成员运行PowerShell修改用户密码脚本时遭遇访问被拒的问题求助

各位好,我现在碰到个头疼的问题想请教大家:

我有几台属于工作组的服务器,需要给这些服务器上的用户修改密码。为了测试流程,我先在本地创建了一个账号,把它加入了本地管理员组,然后用这个新账号启动了PowerShell。

我执行的修改密码脚本是这样的:

$NewPass = Read-Host -Prompt “Provide New Password” -AsSecureString
Get-LocalUser "test" | Set-LocalUser -Password $NewPass

结果刚运行就报错了:

Set-LocalUser : Access denied.
At line:1 char:24

  • Get-LocalUser "test" | Set-LocalUser -Password $NewPass

我特意写了个小函数检查当前PowerShell窗口是否处于提权状态,结果返回的是false:

function Test-IsElevated {
    $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
    $p = New-Object System.Security.Principal.WindowsPrincipal($id)
    if ($p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator))
    { Write-Output $true }
    else
    { Write-Output $false }
}

目前我发现,只有……

备注:内容来源于stack exchange,提问作者Daniel Olsson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 14:18:13