# Modify terminalservicesprofilepath from machine off the domain

**URL:** <https://forums.powershell.org/t/modify-terminalservicesprofilepath-from-machine-off-the-domain/10434>\
**Category:** PowerShell Help\
**Created:** [April 3, 2018, 9:54am UTC](https://forums.powershell.org/t/modify-terminalservicesprofilepath-from-machine-off-the-domain/10434 "2018-04-03T09:54:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![caladin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/caladin/32/358_2.png) [@caladin](https://forums.powershell.org/u/caladin)\
**Post date:** [April 3, 2018, 9:54am UTC](https://forums.powershell.org/t/modify-terminalservicesprofilepath-from-machine-off-the-domain/10434/1 "2018-04-03T09:54:41Z")

</div>

I can run this powershell to set the term svc path, if I’m on the domain controller, but I need to be able to run  
this from a machine that’s a member of a different domain (it’s part of a student domain user creation app run on the staff domain)

```
cls
import-module ActiveDirectory
$user = [ADSI] "LDAP://CN=aaaddd.aaaddd,OU=Alaska Users,OU=Alaska,OU=XXXXX,DC=XXX,DC=XXXX,DC=org";
$user.psbase.Invokeset( "terminalservicesprofilepath", "\\ad\rds\ProfileAlaska\abab.ababf" );
$user.setinfo();

$user
$user.psbase.InvokeGet( "terminalservicesprofilepath" );
```

I know I wrote a script years ago that could update account names from off the domain, but I can’t find it or figure out how  
I did it last time…

The powershell script will be being called from within a webApp that does the rest of character creations.

I’m an old coder, but a noob at powershell. So please feel free to include any links you think I should read to get necessary background info to understand your answer.

Thanks,

Eric-

---

<div class="post-metadata">

**Author:** ![simbrook](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@simbrook](https://forums.powershell.org/u/simbrook)\
**Post date:** [April 3, 2018, 10:26am UTC](https://forums.powershell.org/t/modify-terminalservicesprofilepath-from-machine-off-the-domain/10434/2 "2018-04-03T10:26:23Z")

</div>

you could use New-PSDrive to connect to the other domain see [Crusader Two-One | Write an awesome description for your new site here. You can edit this line in \_config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.](http://www.joseph-streeter.com/?p=799) then you can switch to this domain in powershell. Any commands you type in the shell will be run on the PS drive domain

---

<div class="post-metadata">

**Author:** ![caladin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/caladin/32/358_2.png) [@caladin](https://forums.powershell.org/u/caladin)\
**Post date:** [April 3, 2018, 10:50am UTC](https://forums.powershell.org/t/modify-terminalservicesprofilepath-from-machine-off-the-domain/10434/3 "2018-04-03T10:50:01Z")

</div>

Sorry, on more clarification,

How can I set the password, so this can be called from within another process?

I didn’t ass that part to keep the question focused, but I’m going to run the script from an application… so I need to embed the  
user/password…

I’ll go add that to the original question…

This is what I was able to get from your link…

but I get the same error as when running on the wrong server before

```
cls
import-module ActiveDirectory

$Username = 'ad\xxxxTac'
$Password = 'xxxxx'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force

$SecureString = $pass
# Users you password securly
$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString 

if (-not(Get-PSDrive DomainServer223)) {
    #do the psdrive set up sp it runs remotely
New-PSDrive `
    –Name DomainServer223 `
    –PSProvider ActiveDirectory `
    –Server 'XXXXXXX' `
    –Credential ($MySecureCreds) `
    –Root "//RootDSE/" `
    -Scope Global
    }Else{
    "Drive already exists"
    }

cd DomainServer223:

#set the term path
$user = [ADSI] "LDAP://CN=aaaddd.aaaddd,OU=Alaska Users,OU=Alaska,OU=Cxxxs,DC=xx,DC=xxxx,DC=xxx";

$user.psbase.Invokeset( "terminalservicesprofilepath", "\\ad\rds\ProfileAlaska\abab.ababf" );
$user.setinfo();

$user
$user.psbase.InvokeGet( "terminalservicesprofilepath" );
```

**Exception calling “InvokeSet” with “2” argument(s): "A referral was returned from the server.  
"  
At C:\Users\Brown.ericw\Documents\test termservscriptpath setter.ps1:32 char:1**

 
**- $user.psbase.Invokeset( “terminalservicesprofilepath”, "\ad\rds\Prof …
-** 

**```auto
  + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
  + FullyQualifiedErrorId : DotNetMethodException**

**```**

 

**The following exception occurred while retrieving member “setinfo”: "A referral was returned from the server.  
"  
At C:\Users\Brown.ericw\Documents\test termservscriptpath setter.ps1:33 char:1**

 
**- $user.setinfo();
-** 

**```auto
  + CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException
  + FullyQualifiedErrorId : CatchFromBaseGetMember**

**```**

 

**The following exception occurred while retrieving member “distinguishedName”: "A referral was returned from the server.  
"  
At :line:0 char:0**

Thanks,

Eric-

---

<div class="post-metadata">

**Author:** ![caladin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/caladin/32/358_2.png) [@caladin](https://forums.powershell.org/u/caladin)\
**Post date:** [April 3, 2018, 11:13am UTC](https://forums.powershell.org/t/modify-terminalservicesprofilepath-from-machine-off-the-domain/10434/4 "2018-04-03T11:13:55Z")

</div>

It looks like I’m making the ps drive, but I’m getting the same error as before

```
cls
import-module ActiveDirectory

$Username = 'xxxxx'
$Password = 'xxxxxx'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force

$SecureString = $pass
# Users you password securly
$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString 

if (-not(Get-PSDrive DomainServer223)) {
    #do the psdrive set up sp it runs remotely
New-PSDrive `
    –Name DomainServer223 `
    –PSProvider ActiveDirectory `
    –Server 'xxxxx' `
    –Credential ($MySecureCreds) `
    –Root "//RootDSE/" `
    -Scope Global
    }Else{
    "Drive already exists"
    }

cd DomainServer223:

#set the term path
$user = [ADSI] "LDAP://CN=aaaddd.aaaddd,OU=Alaska Users,OU=Alaska,OU=Centers,DC=xxx,DC=xxx,DC=org";

$user.psbase.Invokeset( "terminalservicesprofilepath", "\\ad\rds\ProfileAlaska\abab.ababf" );
$user.setinfo();

$user
$user.psbase.InvokeGet( "terminalservicesprofilepath" );
```

* * *

## the output

Drive already exists  
Exception calling “InvokeSet” with “2” argument(s): "A referral was returned from the server.  
"  
At C:\Users\Brown.ericw\Documents\test termservscriptpath setter.ps1:32 char:1

- $user.psbase.Invokeset( “terminalservicesprofilepath”, "\ad\rds\Prof …
- 

```auto
  + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
  + FullyQualifiedErrorId : DotNetMethodException

```

The following exception occurred while retrieving member “setinfo”: "A referral was returned from the server.  
"  
At C:\Users\Brown.ericw\Documents\test termservscriptpath setter.ps1:33 char:1

- $user.setinfo();
- 

```auto
  + CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException
  + FullyQualifiedErrorId : CatchFromBaseGetMember

```

The following exception occurred while retrieving member “distinguishedName”: "A referral was returned from the server.  
"  
At :line:0 char:0

Thanks,

Eric-

---

<div class="post-metadata">

**Author:** ![caladin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/caladin/32/358_2.png) [@caladin](https://forums.powershell.org/u/caladin)\
**Post date:** [April 4, 2018, 11:24am UTC](https://forums.powershell.org/t/modify-terminalservicesprofilepath-from-machine-off-the-domain/10434/5 "2018-04-04T11:24:36Z")

</div>

Follow up research seems to indicate the PDrive only works with the activedirectory components not the ADSI components,  
I’m guessing this is why ps-drive isnt’ have any effect on this script.

Are there any ways to make the adsi stuff correctly save across domains?

Thanks,

Eric-

---

<div class="post-metadata">

**Author:** ![caladin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/caladin/32/358_2.png) [@caladin](https://forums.powershell.org/u/caladin)\
**Post date:** [April 6, 2018, 9:17am UTC](https://forums.powershell.org/t/modify-terminalservicesprofilepath-from-machine-off-the-domain/10434/6 "2018-04-06T09:17:34Z")

</div>

The answer turned out to be using a ps-session, so that it could be wrapped in something that took a credential

[https://stackoverflow.com/questions/49581128/modify-terminalservicesprofilepath-in-powershell-from-a-machine-that-is-non-a-me](https://stackoverflow.com/questions/49581128/modify-terminalservicesprofilepath-in-powershell-from-a-machine-that-is-non-a-me)

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:36pm UTC](https://forums.powershell.org/t/modify-terminalservicesprofilepath-from-machine-off-the-domain/10434/7 "2024-05-16T20:36:02Z")

</div>


