![提升权限的Powershell脚本仍然权限不足](https://linux22.com/image/1525854/%E6%8F%90%E5%8D%87%E6%9D%83%E9%99%90%E7%9A%84Powershell%E8%84%9A%E6%9C%AC%E4%BB%8D%E7%84%B6%E6%9D%83%E9%99%90%E4%B8%8D%E8%B6%B3.png)
我之前确实运行过这个这个问题但由于某种原因,我收到消息“以完全权限运行”,但我的脚本仍然引发异常:
get-brokersession : Insufficient administrative privilege
+ CategoryInfo : PermissionDenied:
我的脚本:
param([switch]$Elevated)
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test-Admin) -eq $false) {
if ($elevated)
{
# tried to elevate, did not work, aborting
}
else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}
'running with full privileges'
$hostname=$args[0]
$Logfile = "C:\Program Files\NSClient++\log\logout_user.log"
$Stamp = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
Function LogWrite
{
Param ([string]$logstring)
Add-content $Logfile -value $logstring
}
Add-PSSnapin Citrix.*
get-brokersession -HostedMachineName $hostname -filter {sessionstate -eq "Disconnected"} | stop-brokersession
LogWrite "$Stamp Server: $hostname - stopped brokersessions, inactive Users cleared"
Write-Host "Server: $hostname - stopped brokersessions, inactive Users cleared"
编辑:运行脚本的服务正在使用在此计算机上具有本地管理员权限的托管服务帐户运行。就像我说的,它以前有效,我不确定发生了什么变化......如果有任何变化的话......
编辑2:这个问题更像是在问为什么我不能运行命令,尽管我应该有完全权限,而不是如何提升我的权限。希望这足以证明一个新的问题
感谢任何帮助。