Share via

Using Invoke-Command using Credentials to run Get-RDRemoteApp fails

Benjamin Peikes 21 Reputation points
2022-04-10T03:28:18.867+00:00

I have a script which I can run locally on our ConnectionBroker, though the session has to be elevated, which manages our RDRemoteApp collections. We're trying to automate processes and remote the requirement of having someone actually log onto the ConnectionBroker to run scripts manually. To do so, we are trying to use Invoke-Command to run the script remotely.
Even though we pass credentials for a user that is in domain administrator group, the following script gives us an error when run remotely:

$server = "ConnectionBrokerName"
$collectionName ="OurCollection"

$password = ConvertTo-SecureString "password" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("DOMAIN\domain_admin", $password)

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

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

This will return an error like:
A Remote Desktop Services deployment does not exist on ConnectionBrokerName.DOMAIN.COM. This operation can be performed after creating a deployment. For information about creating a
deployment, run "Get-Help New-RDVirtualDesktopDeployment" or "Get-Help New-RDSessionDeployment".

  • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
  • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-RDRemoteApp
  • PSComputerName : ConnectionBrokerName
Windows for business | Windows Client for IT Pros | User experience | Remote desktop services and terminal services
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

2 answers

Sort by: Most helpful
  1. Rich Matheisen 48,116 Reputation points
    2022-04-28T21:28:15.653+00:00

    Are you use a high-availabilty setup?

    (Get-RDConnectionBrokerHighAvailability -ConnectionBroker).ActiveManagementServer
    

    Does this work? And, if it does, do you get the name of the server you expect?

    Was this answer helpful?


  2. Rich Matheisen 48,116 Reputation points
    2022-04-10T14:59:05.253+00:00

    The value of $collectionName needs to be passed as a parameter to the script block.

    Try using (no pun intended) something like this:

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

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.