# Join to Domain through USB?

**URL:** <https://forums.powershell.org/t/join-to-domain-through-usb/25710>\
**Category:** PowerShell Help\
**Created:** [April 18, 2025, 2:26pm UTC](https://forums.powershell.org/t/join-to-domain-through-usb/25710 "2025-04-18T14:26:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dzdz](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@dzdz](https://forums.powershell.org/u/dzdz)\
**Post date:** [April 18, 2025, 2:26pm UTC](https://forums.powershell.org/t/join-to-domain-through-usb/25710/1 "2025-04-18T14:26:43Z")

</div>

HI everyone,

I need to join different computers to a domain. I always did it through wmic commands in a bat file, no problem till now. Now the wmic command is deprecated (Win11) and i’m trying to find a way to join.

before i used this:

`wmic computersystem where name="%computername%" call joindomainorworkgroup fjoinoptions=3 name=domain username=domain\user Password="password"`

Now i’m trying to accomplish it through powershell that looks like this:

`$domain = "domain"`

`$password = "password" | ConvertTo-SecureString -asPlainText -Force`

`$username = "$domain\user"`

`$credential = New-Object System.Management.Automation.PSCredential($username,$password)`

`Add-Computer -DomainName $domain -Credential $credential`

The script works when launched from an administrative powershell session. But i’d like to run it from my USB. I tried/encountered the following errors:

1- **Execution Policy**

I don’t want to disable execution policy for each machine, but just temporarily. I worked around this doing a .bat file that calls the .ps1 file bypassing execution policy:

`powershell -ExecutionPolicy Bypass -File script.ps1`

The script run, but it says “access denied” because it needs an administrative powershell session.

2- **Executing Powershell as admin user??**

The second and most annoying one is that the script won’t run in an admin console, even if the bat file has run as admin. So i tried doing this bat file:

`powershell -noexit -ExecutionPolicy Bypass -Command "Start-Process -Verb RunAs powershell -ArgumentList '-ExecutionPolicy Bypass -File .\joinwsm.ps1'"`

But the script just won’t do anything. If I remove the “ArgumentList” part, it correctly opens a powershell terminal window as admin.

I’ve been trying for too much time right now, maybe the thing is simpler than i think 🙂

Any help/suggestion would be appreciated, thank you!

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [April 18, 2025, 2:53pm UTC](https://forums.powershell.org/t/join-to-domain-through-usb/25710/2 "2025-04-18T14:53:55Z")

</div>

All you need is  
`Add-Computer -Credential $(Get-Credential)`

The credential will be those with privs to join a computer to the domain

---

<div class="post-metadata">

**Author:** ![dzdz](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@dzdz](https://forums.powershell.org/u/dzdz)\
**Post date:** [April 18, 2025, 3:07pm UTC](https://forums.powershell.org/t/join-to-domain-through-usb/25710/3 "2025-04-18T15:07:32Z")

</div>

Hi, that’s not the case. It’s not a problem with my user (the join script works)  
The problem is with runninr that script in an administrative powershell session from a USB device

---

<div class="post-metadata">

**Author:** ![Austin\_H](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/austin_h/32/4523_2.png) [@Austin\_H](https://forums.powershell.org/u/Austin_H)\
**Post date:** [April 18, 2025, 3:42pm UTC](https://forums.powershell.org/t/join-to-domain-through-usb/25710/4 "2025-04-18T15:42:34Z")

</div>

Hi @dzdz,

Is the code blocked on the USB drive? If a script is uploaded to somewhere it wasn’t originally created (in a run time environment such as being downloaded from GitHub or another device), the code can be blocked and prevented from running. Check this first and let us know.

---

<div class="post-metadata">

**Author:** ![dzdz](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@dzdz](https://forums.powershell.org/u/dzdz)\
**Post date:** [April 18, 2025, 4:14pm UTC](https://forums.powershell.org/t/join-to-domain-through-usb/25710/5 "2025-04-18T16:14:14Z")

</div>

Hi everyone, I found the solution!  
Thank you @Austin_H , but that was not the problem, it was much simplier than I thought! The script in fact works BUT it opens an administrative shell in C:, and couldn’t find the script passed in the arguments cause it is on my usb stick (D:\ in this case). SoI simply specified the path for my script and now it looks like this:

`powershell -noexit -ExecutionPolicy Bypass -Command "Start-Process -Verb RunAs powershell -ArgumentList '-ExecutionPolicy Bypass -File D:\joinwsm.ps1'"`

Powershell was not the problem in the end 🙂

Thank you all for your help!

---

<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:** [May 18, 2025, 4:15pm UTC](https://forums.powershell.org/t/join-to-domain-through-usb/25710/6 "2025-05-18T16:15:10Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
