?
Solved

Powershell join domain full automation

Posted on 2013-06-03
8
Medium Priority
?
532 Views
Last Modified: 2014-10-25
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.Automation.PSCredential($username,$password)
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_InvalidArgument,Microsoft.Pow
   erShell.Commands.ConvertToSecureStringCommand

---------------------------------------------------------------------------------------
0
Comment
Question by:revenuecyclepartners
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 23

Expert Comment

by:Stelian Stan
ID: 39216763
0
 
LVL 40

Accepted Solution

by:
footech earned 2000 total points
ID: 39217469
You can use just WDS for this.  The image unattend file doesn't need to have credentials stored in it if you do an unsecure join (don't let the term fool you, there's nothing to worry about).  See here:
http://technet.microsoft.com/en-us/library/cc730845(v=ws.10).aspx
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39219575
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?
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:revenuecyclepartners
ID: 39227100
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
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39227173
I hope you are using the same account to create and read the password..
0
 

Author Comment

by:revenuecyclepartners
ID: 39244750
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question