title: Remote Desktop Services: CAP or RAP through PowerShell
body: <p>I am trying to configure a new RDS gateway server through Powershell (for automatic setup after EC2 creation). The issue I'm running into right now is setting up a default or otherwise CAP and RAP. Everything else seems to work just fine, and if I go through the server dialogs and point and click my way to doing the CAP/RAP wizard, it all works. Until I do so, those policies don't exist (not even a default).</p>
  
  <p>The code I'm using, which I sourced from blog posts on technet about the subject, is this:</p>
  
  <pre><code>new-item -Force -Credential $AdminCredentials -path RDS:\GatewayServer\CAP -Name DomainAdmin-CAP -UserGroups “$AdminGroupName@$NetBiosDomainName" -AuthMethod 1
  new-item -Force -Credential $AdminCredentials -path RDS:\GatewayServer\CAP -Name DomainUser-CAP -UserGroups “$UserGroupName@$NetBiosDomainName" -AuthMethod 1
  
  new-item -Force -Credential $AdminCredentials -path RDS:\GatewayServer\RAP -Name DomainAdmin-RAP -UserGroups “$AdminGroupName@$NetBiosDomainName" -ComputerGroupType 2
  new-item -Force -Credential $AdminCredentials -path RDS:\GatewayServer\RAP -Name DomainUser-RAP -UserGroups “$UserGroupName@$NetBiosdomainName" -ComputerGroupType 2
  </code></pre>
  
  <p>Again, everything else works and the system is 100% and useable once I RDP in to the server and set these up manually, so my only issue is this automation step. The error I'm getting when I run my script is this:</p>
  
  <blockquote>
    <p>new-item : Access to the object at RDS:\GatewayServer\CAP\DomainAdmin-CAP is denied for the cmdlet
    New-Item.The supplied  value is not valid, or you do not have
    sufficient permissions. At line:89 char:1
    + new-item -Force -Credential $AdminCredentials -path RDS:\GatewayServe ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : PermissionDenied: (:) [New-Item], AccessViolationException
        + FullyQualifiedErrorId : PermissionDenied,Microsoft.PowerShell.Commands.NewItemCommand</p>
  </blockquote>
  
  <p>Edit: Things I have tried based on suggestions and frustration:</p>
  
  <p>I have made all " characters uniform after someone pointed out they were actually not the same thing on the front and rear of my -UserGroup variable strings - No error change.</p>
  
  <p>I have tried $NetBiosDomainName as the simple one word NetBIOS version (DOMAIN) as well as the full domain (domain.company.com) - No error change.</p>
  
  <p>I have tried changing the "$AdministratorsGroupName@$NetBiosDomainName" string out for $AdminGroup (= $AdministratorsGroupName + "@" + $NetBiosDomainName") to simplify the input to the -UserGroups parameter - No error change</p>
  
  <p>I have run this script as both the domain admin and local administrator account - No error change</p>