revenuecyclepartners
asked on
Powershell join domain full automation
I'm trying to create a script to completely automate joining the domain to use during a wds image deployment. I don't want to use the WAIK option because the password is stored in plain text in the xml file. So I've found some powershell scripts online that look like they could work.
This is the command I used to create my encrypted file which contains the password.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -
read-host -assecurestring | convertfrom-securestring | out-file C:\securestring.txt
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -
Here's the script I'm using.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -
$domain = "MYDOMAIN.COM"
$password = cat C:\securestring.txt | ConvertTo-SecureString -Force
$username = "$domain\MYUSERNAME"
$credential = New-Object System.Management.Automati on.PSCrede ntial($use rname,$pas sword)
Add-Computer -DomainName $domain -Credential $credential
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -
Here's the error I'm getting.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -
C:\>powershell
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\> $domain = "MYDOMAIN.COM"
PS C:\> $password = cat C:\securestring.txt | ConvertTo-Secure
String -Force
ConvertTo-SecureString : Cannot process argument because the value of argument
"input" is invalid. Change the value of the "input" argument and run the operat
ion again.
At line:1 char:66
+ $password = cat C:\securestring.txt | ConvertTo-SecureString <<<< -Forc
e
+ CategoryInfo : InvalidArgument: (:) [ConvertTo-SecureString], P
SArgumentException
+ FullyQualifiedErrorId : ImportSecureString_Invalid Argument,M icrosoft.P ow
erShell.Commands.ConvertTo SecureStri ngCommand
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -
This is the command I used to create my encrypted file which contains the password.
--------------------------
read-host -assecurestring | convertfrom-securestring | out-file C:\securestring.txt
--------------------------
Here's the script I'm using.
--------------------------
$domain = "MYDOMAIN.COM"
$password = cat C:\securestring.txt | ConvertTo-SecureString -Force
$username = "$domain\MYUSERNAME"
$credential = New-Object System.Management.Automati
Add-Computer -DomainName $domain -Credential $credential
--------------------------
Here's the error I'm getting.
--------------------------
C:\>powershell
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\> $domain = "MYDOMAIN.COM"
PS C:\> $password = cat C:\securestring.txt | ConvertTo-Secure
String -Force
ConvertTo-SecureString : Cannot process argument because the value of argument
"input" is invalid. Change the value of the "input" argument and run the operat
ion again.
At line:1 char:66
+ $password = cat C:\securestring.txt | ConvertTo-SecureString <<<< -Forc
e
+ CategoryInfo : InvalidArgument: (:) [ConvertTo-SecureString], P
SArgumentException
+ FullyQualifiedErrorId : ImportSecureString_Invalid
erShell.Commands.ConvertTo
--------------------------
Have a look on this script: http://thesurlyadmin.com/2012/08/10/single-click-script-to-add-a-computer-to-the-domain/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ConvertTo-SecureString : Cannot process argument because the value of argument "input" is invalid. Change the value of the "input" argument and run the operation again.Regarding your error..
Ideally your command should work without any error..
read-host -assecurestring | convertfrom-securestring | out-file C:\securestring.txt
$password = cat C:\securestring.txt | ConvertTo-SecureString -Force
The error possibly means your first command failed to create password and save it to the file..
Are you getting any output for command cat C:\securestring.txt?
ASKER
Yes cat C:\securestring.txt outputs what looks like encrypted text.
I've also tried creating the password file with he following commands and have had similar errors.
$password = "PASSWORD"
$secure = ConvertTo-SecureString $password -force -asPlainText
$bytes = ConvertFrom-SecureString $secure
$bytes | Out-File secureString.txt
I've also tried creating the password file with he following commands and have had similar errors.
$password = "PASSWORD"
$secure = ConvertTo-SecureString $password -force -asPlainText
$bytes = ConvertFrom-SecureString $secure
$bytes | Out-File secureString.txt
I hope you are using the same account to create and read the password..
ASKER
I tried creating and using the encrypted password file from the same user as well as from different user accounts with no luck.
It doesn't make sense to me that you can only create and use a password file while logged in as that user, what's the point of having the cred file if you can't use it to auto logon for instance when joining the domain. Before I join the domain I'm logged on to the comptuer with a local user account and the domain is going to ask me for domain creds when I send the join domain request.
It doesn't make sense to me that you can only create and use a password file while logged in as that user, what's the point of having the cred file if you can't use it to auto logon for instance when joining the domain. Before I join the domain I'm logged on to the comptuer with a local user account and the domain is going to ask me for domain creds when I send the join domain request.