Link to home
Start Free TrialLog in
Avatar of Sean
SeanFlag for United States of America

asked on

Powershell/Vb Script to rename PC and add to a domain using encrypted domain credentials

Hello,
I need a script to rename a computer and join it to the domain. I need the domain credentials to be encrypted since this task is being out sourced.

Thank you
Avatar of Member_2_760301
Member_2_760301
Flag of Ireland image

Hi,

You need to request user's input or you need to have already stored data inside?

If you need to encrypt the data and send it like this you can use this case to encrypt it:

$password = "password" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString

Once encrypt it you use the new variable like this:

$password = "01000000d08c9ddf0115d1118c7a00c04fc297eb01000000b9fe0ca15a2ffb4a9e172d76a87afae40000000002000000000003660000c000000010000000875eab73cc326c4acb70b609f170da6d0000000004800000a0000000100000001efe13d29355bea97995960f306c0009180000005a906fee5e408ccf685bbc56dd1c3e3c91472d168c17d38a140000008bf9a9f060d1c46d1d96441d2080218ff0ada1a6"

Otherwise:
To rename use:
$computername = Read-Host -Prompt "Enter computer name $computername"
$domain = "myDomain"
$user = "myUserAccount"
$password = Read-Host -Prompt "Enter password for $user" -AsSecureString
$credential = "$domain\$user"
Rename-computer –newname $computername –domaincredential $credential –force

To add it in AD:
$credentialObject = New-Object System.Management.Automation.PSCredential($user,$password)
Add-Computer -DomainName $domain -Credential $credentialObject
Avatar of Sean

ASKER

Cristian ,
Thank you. Will try it and provide feedback asap.
Sean
Sean,

Re-reading the sample code, I found a mistake:
$password = Read-Host -Prompt "Enter password for $user" -AsSecureString

Thinking faster than I type :)

Correct the line in:
$password = Read-Host -Prompt "Enter password for $password" -AsSecureString
You can delegate the domain join permissions to a normal account on a particular OU.
This is safer.

If the account you are using above is a domain admin then you are at risk even with an encrypted password.
Avatar of Sean

ASKER

Nagendra,

trying your suggestion also. Will provide feedback.
Thank you very much
Sean
Avatar of Sean

ASKER

Cristian,
Have some issues that I need to work out with your script. I am looking for a script that would only ask for the new computer name. The domain credentials should already be in the script. Would be nice to have the password encrypted  even-though I am using the "Delegate Control" in AD as Nagendra kindly suggested.

Thanks agian
Sean
ASKER CERTIFIED SOLUTION
Avatar of Member_2_760301
Member_2_760301
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sean

ASKER

Hi Cristian,

Does not like  "//already encrypted"  

Thank you for your time
Sean
Hi Sean,

Remove that :-) It was a note for you.

Regards
Avatar of Sean

ASKER

Very sorry for not responding sooner. Some fires that need to be put out first. Will update as soon as possible.
Thanks
Sean
Avatar of Sean

ASKER

Thank you Cristian.