Link to home
Start Free TrialLog in
Avatar of us-pata
us-pata

asked on

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

Avatar of dnairns
dnairns

Are you talking about passing the users password?
Avatar of us-pata

ASKER

Yes. I need to use an option like -password 'Pass1234' in the command string
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

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.
Avatar of Raj-GT
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
Avatar of us-pata

ASKER

But i still have to input the password. that is what i am trying to avoid.
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.
Avatar of us-pata

ASKER

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'
You forgot a space between password and $password
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'
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'
Avatar of us-pata

ASKER

Raj-GT can you put the command in code viewer? the formatting on this page breaks the line and spaces
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!
ASKER CERTIFIED SOLUTION
Avatar of dnairns
dnairns

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 us-pata

ASKER

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
then add this line and call it a day:
 
$password = ConvertTo-SecureString -string "Abcd1234" -asPlainText -force
Avatar of us-pata

ASKER

Works perfectly :)
Isn't that my answer?