Invoke-Command not running with elevated privilages even though credentials are being passed

Benjamin Peikes 16 Reputation points
2022-04-18T15:11:38.153+00:00

We have a server which is acting as a remote desktop connection broker, gateway and host. We want to be able to automate some of our administrative tasks so we don't have to have someone log into the machine. Here is a summary of the issue:

  1. I can remote into the machine using a set of credentials which have domain administrator privileges. If I run Get-RDRemoteApp from a regular PowerShell window I get the error:
    Get-RDRemoteApp : A Remote Desktop Services deployment does not exist on XXXXXXXXX.........

2) I then "Run ISE as Administrator" on the same machine in the same session, and Get-RDRemoteApp returns the list of applications in the collection we have

3) From a different machine, I use Invoke-Command, with the -Credentials passed in, like this:

$password_sec = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($admin_user, $password_sec)

$sb =
{
    Import-Module RemoteDesktop
    Import-Module RemoteDesktopServices
    Get-RDRemoteApp -CollectionName 
}

Invoke-Command -Credential $cred -ComputerName $server -ScriptBlock $sb 

This returns the "Get-RDRemoteApp : A Remote Desktop Services deployment does not exist on XXXXXXXXX........." error. It appears that Invoke-Command is not running with elevated permissions for some reason. I've read that if the credentials of the user passed in have administrative rights, there should be no issue.

Is it possible that there is no way to remotely administrate remote desktop servers?

Remote Desktop
Remote Desktop
A Microsoft app that connects remotely to computers and to virtual apps and desktops.
4,406 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
{count} votes