# using powershell across domains

**URL:** <https://forums.powershell.org/t/using-powershell-across-domains/3573>\
**Category:** PowerShell Help\
**Created:** [December 30, 2014, 8:18am UTC](https://forums.powershell.org/t/using-powershell-across-domains/3573 "2014-12-30T08:18:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![darrencohen747](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@darrencohen747](https://forums.powershell.org/u/darrencohen747)\
**Post date:** [December 30, 2014, 8:18am UTC](https://forums.powershell.org/t/using-powershell-across-domains/3573/1 "2014-12-30T08:18:16Z")

</div>

Newbie here…

I have a computer in one domain that I am authenticating to (because we were acquired recently and pc changed), but our primary network is our old domain, and I want to run powershell commands against our “old domain” How can I authenticate, login, or run commands on the “old domain” from my “new” computer with a different domain.

For example… my computer is domain x, and logging in with an account from domain x.  
but I want to access powershell commands all on domain y , with a different AD account that belongs to domain y.

Thanks so much!!

Here’s an output of the error:  
Get-Service : Cannot open Service Control Manager on computer ‘xyz’. This operation might require other privileges  
At line:1 char:1

- Get-Service -ComputerName xyz
- 

```auto
  + CategoryInfo : NotSpecified: (:) [Get-Service], InvalidOperationException
  + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetServiceCommand
```

---

<div class="post-metadata">

**Author:** ![will-anderson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/will-anderson/32/234_2.png) [@will-anderson](https://forums.powershell.org/u/will-anderson)\
**Post date:** [December 30, 2014, 8:54am UTC](https://forums.powershell.org/t/using-powershell-across-domains/3573/2 "2014-12-30T08:54:52Z")

</div>

A lot of PowerShell cmdlets support the use of the -Credential parameter, allowing you to use alternate credentials. There’s also the Invoke-Command cmdlet that you can use with -Credential, and then pass a cmdlet through that if the original cmdlet doesn’t support -Credential. For instance:

Invoke-Command -ComputerName %Server% -Credential domain\user {Get-Service}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [December 30, 2014, 9:12am UTC](https://forums.powershell.org/t/using-powershell-across-domains/3573/3 "2014-12-30T09:12:05Z")

</div>

Going along with Will’s suggestion, you can determine what cmdlets accept the -Credential parameter by using the Get-Command cmdlet: Get-Command -ParameterName Credential | Sort-Object Name. I have a function in my profile that will prompt me for a password that I can then use to connect to a different domain. I also have a Set-Alias in my profile that helps me avoid typing the whole function name.

```
Function New-OtherDomainCred {
    $Global:odcred = Get-Credential -UserName 'otherdomain\username' -Message 'Create OtherDomain Credential Object'
}
```

After running this function, my credential object would be stored in $odcred, so I can use it as the value for the -Credential parameter.

---

<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:46pm UTC](https://forums.powershell.org/t/using-powershell-across-domains/3573/4 "2024-05-16T20:46:34Z")

</div>


