How can i create a user without beeing prompted for password on Exchange 2007 Powershell console?

I need to know if there is a way to create new users with a simple command without beeing prompted for input. I want something like -passord 'Pass1234' thingy, but that doesnt work.

Any ideas?
New-Mailbox -Name '".$fullname[$i]."' -Alias '".$username."' -OrganizationalUnit '".$OU."' -UserPrincipalName '".$username."@".$upndomain[$i]."' -SamAccountName '".$samname."' -FirstName '".$name[1]."' -Initials '' -LastName '".$name[0]."' -ResetPasswordOnNextLogon \$false -Database 'WWW\E-Service KT\E-Service KT - 100MB'

Open in new window

LVL 1
us-pataAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dnairnsCommented:
Are you talking about passing the users password?
0
us-pataAuthor Commented:
Yes. I need to use an option like -password 'Pass1234' in the command string
0
dnairnsCommented:
Try this if you are trying to set the users password.

read-host -assecurestring | convertfrom-securestring | out-file .\Credentials.txt
 
$password = get-content .\Credentials.txt | convertto-securestring
 
New-Mailbox -Name '".$fullname[$i]."' -Alias '".$username."' -OrganizationalUnit '".$OU."' -Password $password -UserPrincipalName '".$username."@".$upndomain[$i]."' -SamAccountName '".$samname."' -FirstName '".$name[1]."' -Initials '' -LastName '".$name[0]."' -ResetPasswordOnNextLogon \$false -Database 'WWW\E-Service KT\E-Service KT - 100MB' 
 
 

Open in new window

0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

dnairnsCommented:
You need to pass the password as a secure string. This will ask for the password, store it in a file in the current directory in a file and then you can create the object by inputting line 3 and then you can pass it to the -password parameter.
If you don't want to have to type this in every time, put line 3 in your profile or in a script that executes whenever you open the Exchange 2007 PS console, and make sure the file is somewhere secure and that no one deletes it.
0
Raj-GTSystems EngineerCommented:
You need to create the password as a secure string variable and pass it to your script

$password = "Abcd1234"
$securepassword = ConvertTo-SecureString -string $mypassword -asPlainText -force

now you can pass the $securepassword to your script.

Hope this helps.

Regards,
Raj
0
us-pataAuthor Commented:
But i still have to input the password. that is what i am trying to avoid.
0
dnairnsCommented:
Mine will store it in a file to be used later. You glkist input it once to store it in the file. From there you just need to set to set up the profile to pass line 3 when the console is initialized. This will make it so the password object will be the same.
0
us-pataAuthor Commented:
i get this error:

[PS] C:\Documents and Settings\Administrator\Desktop\newusers>New-Mailbox -Name
'test1' -Alias 'test1' -OrganizationalUnit 'mailpost.no/Users' -UserPrincipalNam
e 'test1@mailpost.no' -SamAccountName 'test1' -FirstName 'test1' -Initials '' -L
astName 'test1' -Password$password -ResetPasswordOnNextLogon $false -Database 'W
WW\E-Service KT\E-Service KT - 1GB'
New-Mailbox : A parameter cannot be found that matches parameter name 'Password
$password'.
At line:1 char:213
+ New-Mailbox -Name 'test1' -Alias 'test1' -OrganizationalUnit 'mailpost.no/Use
rs' -UserPrincipalName 'test1@mailpost.no' -SamAccountName 'test1' -FirstName '
test1' -Initials '' -LastName 'test1' -Password$password  <<<< -ResetPasswordOn
NextLogon $false -Database 'WWW\E-Service KT\E-Service KT - 1GB'
0
dnairnsCommented:
You forgot a space between password and $password
0
Raj-GTSystems EngineerCommented:
Try this in one line

$password = "Abcd1234" ; $securepassword = ConvertTo-SecureString -string $mypassword -asPlainText -force; New-Mailbox -Name
'test1' -Alias 'test1' -OrganizationalUnit 'mailpost.no/Users' -UserPrincipalNam
e 'test1@mailpost.no' -SamAccountName 'test1' -FirstName 'test1' -Initials '' -L
astName 'test1' -Password$password -ResetPasswordOnNextLogon $false -Database 'W
WW\E-Service KT\E-Service KT - 1GB'
0
dnairnsCommented:
you can even shorten that last 'one liner' as follows:
$securepassword = ConvertTo-SecureString -string "Abcd1234" -asPlainText -force; New-Mailbox -Name
'test1' -Alias 'test1' -OrganizationalUnit 'mailpost.no/Users' -UserPrincipalNam
e 'test1@mailpost.no' -SamAccountName 'test1' -FirstName 'test1' -Initials '' -L
astName 'test1' -Password$password -ResetPasswordOnNextLogon $false -Database 'W
WW\E-Service KT\E-Service KT - 1GB'
0
us-pataAuthor Commented:
Raj-GT can you put the command in code viewer? the formatting on this page breaks the line and spaces
0
dnairnsCommented:
you can edit the profile and never have to create the password again.
1. notepad $profile
2. input: $password = get-content .\Credentials.txt | convertto-securestring
3. save file and close
4. restart powershell
5. Try the command and you can use $password for any new user you create.
Good luck!
0
dnairnsCommented:
try it like this.
$password = ConvertTo-SecureString -string "Abcd1234" -asPlainText -force; New-Mailbox -Name '".$fullname[$i]."' -Alias '".$username."' -OrganizationalUnit '".$OU."' -Password $password -UserPrincipalName '".$username."@".$upndomain[$i]."' -SamAccountName '".$samname."' -FirstName '".$name[1]."' -Initials '' -LastName '".$name[0]."' -ResetPasswordOnNextLogon \$false -Database 'WWW\E-Service KT\E-Service KT - 100MB' 
 
  

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
us-pataAuthor Commented:
dnairns: i don't think you get what i am trying to do.
i have a script that generates usernames and password, and that is why i need to do it all in powershell
0
dnairnsCommented:
then add this line and call it a day:
 
$password = ConvertTo-SecureString -string "Abcd1234" -asPlainText -force
0
us-pataAuthor Commented:
Works perfectly :)
0
Raj-GTSystems EngineerCommented:
Isn't that my answer?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.