# set password in join domain script

**URL:** <https://forums.powershell.org/t/set-password-in-join-domain-script/6729>\
**Category:** PowerShell Help\
**Created:** [June 29, 2016, 5:28am UTC](https://forums.powershell.org/t/set-password-in-join-domain-script/6729 "2016-06-29T05:28:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremy-smit](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@jeremy-smit](https://forums.powershell.org/u/jeremy-smit)\
**Post date:** [June 29, 2016, 5:28am UTC](https://forums.powershell.org/t/set-password-in-join-domain-script/6729/1 "2016-06-29T05:28:48Z")

</div>

I whant to create a script to when it runs it joins domain automaticaly.

when i do the following $Admin = get-credential domain\user, it popsup with a screen to fill in the password.  
is it possible to make the script so that if i run it joins domain auto?

Script so far below

$Admin = get-credential domain\admin [password?]

Add-Computer -DomainName domainname.local -Credential $admin -restart

---

<div class="post-metadata">

**Author:** ![mark-prior](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@mark-prior](https://forums.powershell.org/u/mark-prior)\
**Post date:** [June 29, 2016, 5:42am UTC](https://forums.powershell.org/t/set-password-in-join-domain-script/6729/2 "2016-06-29T05:42:12Z")

</div>

not tested as i dont have my laptop but this should work / at least hold the credentials

```
$Username = "Domain\Username"
$Password = ConvertTo-SecureString "Password" -AsPlainText -Force
$Admin = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password

Add-Computer -DomainName domainname.local -Credential $admin -restart
```

---

<div class="post-metadata">

**Author:** ![jeremy-smit](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@jeremy-smit](https://forums.powershell.org/u/jeremy-smit)\
**Post date:** [June 29, 2016, 5:47am UTC](https://forums.powershell.org/t/set-password-in-join-domain-script/6729/3 "2016-06-29T05:47:57Z")

</div>

Seems Legit, i’m gonna test this and will reply back if it worked.  
Thank you so far Mark.

Kind regards, Jeremy

---

<div class="post-metadata">

**Author:** ![jeremy-smit](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@jeremy-smit](https://forums.powershell.org/u/jeremy-smit)\
**Post date:** [June 30, 2016, 12:11am UTC](https://forums.powershell.org/t/set-password-in-join-domain-script/6729/4 "2016-06-30T00:11:44Z")

</div>

@ Mark Prior.

Is it possible to build in the script that powershell will be elevated to administrator?

---

<div class="post-metadata">

**Author:** ![mark-prior](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@mark-prior](https://forums.powershell.org/u/mark-prior)\
**Post date:** [June 30, 2016, 3:31am UTC](https://forums.powershell.org/t/set-password-in-join-domain-script/6729/5 "2016-06-30T03:31:32Z")

</div>

quite a few options discussed here that should help

[http://stackoverflow.com/questions/7690994/powershell-running-a-command-as-administrator](http://stackoverflow.com/questions/7690994/powershell-running-a-command-as-administrator)

cheers

---

<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:41pm UTC](https://forums.powershell.org/t/set-password-in-join-domain-script/6729/6 "2024-05-16T20:41:01Z")

</div>


