# Change Domain first

**URL:** <https://forums.powershell.org/t/change-domain-first/10879>\
**Category:** PowerShell Help\
**Created:** [June 26, 2018, 9:27am UTC](https://forums.powershell.org/t/change-domain-first/10879 "2018-06-26T09:27:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dandor](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@dandor](https://forums.powershell.org/u/dandor)\
**Post date:** [June 26, 2018, 9:27am UTC](https://forums.powershell.org/t/change-domain-first/10879/1 "2018-06-26T09:27:05Z")

</div>

Hi  
I’m trying to clear members of an AD Group and have the working command:  
Get-ADGroupMember “RemoveUpdateTimer” | ForEach-Object {Remove-ADGroupMember “RemoveUpdateTimer” $\_ -Confirm:$false}

The AD Group (RemoveUpdateTimer) and user computers are on ‘Domain A’ and it works locally  
The server that i want to create a scheduled task to run the command daily is on ‘Domain B’

When running the command on the server manually, it says it cannot find the AD Group ‘RemoveUpdateTimer’ on Domain B

Question:  
How can I modify the Powershell command above, to have it look under Domain A, instead of Domain B?

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [June 26, 2018, 10:54am UTC](https://forums.powershell.org/t/change-domain-first/10879/2 "2018-06-26T10:54:20Z")

</div>

The AD commands cue off the drive you’re currently connected to. When you load the module it maps an AD: drive to the domain the computer is a member of, but you can map additions ones (New-PSDrive). Change to the drive that represents a different domain, and the AD commands operate against that domain instead.

This’ll be hard to do in a scheduled task, I imagine, as you’ll have to make sure this isn’t running under the computer’s account, unless the computer’s account somehow has Domain Admin permissions in Domain B.

---

<div class="post-metadata">

**Author:** ![skalizar](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@skalizar](https://forums.powershell.org/u/skalizar)\
**Post date:** [June 26, 2018, 11:43am UTC](https://forums.powershell.org/t/change-domain-first/10879/3 "2018-06-26T11:43:34Z")

</div>

You can add parameters to the AD commands to specify the domain, or a domain controller to use.

Get-ADGroupMember -server [domain.com](http://domain.com) …

Remove-ADGroupMember -server [dc1.domain.com](http://dc1.domain.com) …

You’ll also need to pass credentials if the scheduled job is not running as an admin in that domain.

---

<div class="post-metadata">

**Author:** ![dandor](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@dandor](https://forums.powershell.org/u/dandor)\
**Post date:** [June 26, 2018, 1:06pm UTC](https://forums.powershell.org/t/change-domain-first/10879/4 "2018-06-26T13:06:47Z")

</div>

Thanks, I believe that is closer to a resolution.

The purpose of my command is to remove the members from the AD Group RemoverUpdateTimer. Adding the -server no longer shows an error but also leaves me with nothing to troubleshoot,

Testing from the server domain ‘Domain B’ - no errors, members not removed from AD Group  
Testing from the user domain ‘Domain A’ - no errors, members are removed from the AD Group

How would you add a log output of the command for further troubleshooting…or how would you proceed?

---

<div class="post-metadata">

**Author:** ![dandor](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@dandor](https://forums.powershell.org/u/dandor)\
**Post date:** [June 27, 2018, 7:08am UTC](https://forums.powershell.org/t/change-domain-first/10879/5 "2018-06-27T07:08:35Z")

</div>

Success:

Get-ADGroupMember -identity “RemoveUpdateTimer” -Recursive -Server “DomainB”|ForEach-Object {Remove-ADGroupMember -server “DomainB” “RemoveUpdateTimer” $\_ -Confirm:$false}

---

<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:34pm UTC](https://forums.powershell.org/t/change-domain-first/10879/6 "2024-05-16T20:34:53Z")

</div>

Closed on May 16, 2024, 8:34pm UTC


