Password Needs To Be Manually Set After New-Mailbox cmdlet

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 10 months ago.

  • Author
    Posts
  • #6487

    by djangomonk at 2012-10-18 22:15:37

    Hi,

    I'm new to PowerShell and I'm facing this issue when I create a new Mailbox.

    I have 2 sets of Code Blocks and immaterial of which code block I execute I still have to manually reset the password in ADUC before I can login as that user in OWA.

    Please let me know where I'm going wrong.

    I'm logged into the PowerShell Console as the Domain Administrator
    Exchange 2007
    PowerShell Version
    [size=85]Name : PSVersion
    Value : 2.0
    Name : BuildVersion
    Value : 6.1.7601.17514
    [/size]

    Thanks,
    Sree

    The 2 Code Blocks are Pasted below for your perusal.

    ### Code Block Number 1 ###
    ###
    $First_Name = Read-Host "Enter First Name "
    $Last_Name = Read-Host "Enter Last Name "
    $Display_Name = $First_Name + " " + $Last_Name
    $Account_Name = $First_Name.Substring(0,1).ToLower() + $Last_Name.ToLower()
    $OrgUnit = "OU=UsersEmp,OU=TestUsers,DC=TestDomain,DC=com"
    $MailStore = "TESTEXCH1\Employees"
    $Passwd = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force
    New-Mailbox -FirstName $First_Name -LastName $Last_Name -Name $Display_Name -DisplayName $Display_Name -OrganizationalUnit $OrgUnit -Password $Passwd -Database $MailStore -SamAccountName $Account_Name -UserPrincipalName $Account_Name"@ikanos.com" -ResetPasswordOnNextLogon $true
    ###
    ### Code Block Number 2 ### - Only Change is in the $Passwd line (Line Number: 19) ###
    $First_Name = Read-Host "Enter First Name "
    $Last_Name = Read-Host "Enter Last Name "
    $Display_Name = $First_Name + " " + $Last_Name
    $Account_Name = $First_Name.Substring(0,1).ToLower() + $Last_Name.ToLower()
    $OrgUnit = "OU=TestUsers,DC=TestDomain,DC=com"
    $MailStore = "TESTEXCH1\Employees"
    $Passwd = Read-Host "Enter The User's Password " -AsSecureString
    New-Mailbox -FirstName $First_Name -LastName $Last_Name -Name $Display_Name -DisplayName $Display_Name -OrganizationalUnit $OrgUnit -Password $Passwd -Database $MailStore -SamAccountName $Account_Name -UserPrincipalName $Account_Name"@ikanos.com" -ResetPasswordOnNextLogon $true
    ###

    by DonJ at 2012-10-25 10:52:51

    Sorry you haven't gotten an answer on this yet – by way of troubleshooting, can you run New-MailBox manually without having to reset the password? Does that only happen when you do this from script?

    by djangomonk at 2012-10-25 11:09:14

    Hi DonJ,

    Thanks for your response.
    Yes, your understanding is correct. I face this issue only when I execute this script.
    If I run the cmdlet New-Mailbox then there's no issue.

    Thanks,
    Sree

    by DonJ at 2012-10-25 11:14:08

    Dude, that's weird. If you can go into the shell and manually run those same commands that you have in your script... but they don't work in the script... huh. I'm not at all sure what would do that. It seems as if the password isn't actually getting set in the script, which is what triggers the must-reset-to-enable behavior...

    by djangomonk at 2012-10-25 11:44:04

    Hi DonJ,

    Correction...
    As a workaround I'm only executing the cmdlet & not all the commands from the script into the PowerShell prompt.

    To be precise I execute the following 2 lines in a PowerShell ISE:
    $Passwd = Read-Host "Enter The User's Password " -AsSecureString
    New-Mailbox -FirstName "Test" -LastName "Account" -Name "Test Account" -DisplayName "Test Account" -OrganizationalUnit "OU=UsersEmp,OU=TestUsers,DC=TestDomain,DC=com" -Password $Passwd -Database "TESTEXCH1\Employees" -SamAccountName "taccount" -UserPrincipalName "taccount@testdomain.com" -ResetPasswordOnNextLogon $true

    So my doubt is perhaps with the way all these variables are being handled in the script.
    I already checked but maybe some variable name is a keyword.
    I hope I clarified your question.

    Thanks,
    Sree

    by DonJ at 2012-10-25 11:52:43

    You did. And no, none of those variables are reserved words. I'd probably add, to your script, a line to output $Passwd before running New-Mailbox, just to make sure it really does contain a SecureString. If it does... I'm at a loss. If it works at the command line, and you run that script from the same command-line, the script ought to do the exact same thing.

    It's something that, all things being equal, I might consider submitting to MS product support.

    by djangomonk at 2012-11-06 03:04:54

    Hi Don,

    This issue stands resolved now!
    I am "assuming" that there was some issue with the Test Environment.
    I can't figure out exactly as to what was causing this but when I executed the same script in the Production environment, it worked fine.
    Didn't really spend time to troubleshoot what went wrong in my test environment.
    Thanks for your time & support.

    Regards,
    Sree

You must be logged in to reply to this topic.