i have actually had this running before like in this question but for some reason, I am getting the message "running with full privileges" but still my script throws an exception:
get-brokersession : Insufficient administrative privilege
+ CategoryInfo : PermissionDenied:
My Script:
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"
edit: The service which runs the script is running with a managed-service account which has local admin permissions on this machine. like I said, it worked before, I'm not sure what changed.. if anything changed at all..
edit2: this question is rather asking for why I can not run the commands even though I should have full privileges rather than how to elevate my privileges. Hope this is enough to justify a new question
Appreciate any help.