Script of Exchange 2010 Welcome Message
Hello, I am trying to run script for creating welcome email message to new user. The script is running fine, but i am not receiving any welcome email. THere is no error in script but i am not getting email even after creating new mailbox. Here is the script. Please help how to diagnose whether email is going or not.......... ############################################################################# # New-UserWelcomeEmail.ps1 # Send email to newly created mailboxes # # Pat Richard, MVP # http://ucblogs.net/blogs/exchange # # This script is designed to be run as a Windows Scheduled task on an Exchange # server. See http://www.ucblogs.net/blogs/exchange/archive/2009/10/07/Running-PowerShell-scripts-via-Scheduled-Tasks.aspx # # VERSION COMPATIBILITY # ===================== # Exchange: 2007 # PowerShell: 1.0 # # RIGHTS REQUIRED # =============== # Exchange Recipient Administrator role (unverified) # # UPDATES # ======= # v1.2 03/27/2010 use registry for last run info; variable cleanup # v1.1 05/01/2009 # v1.0 04/30/2009 Initial version # # DEDICATED BLOG POST: # ==================== # None # # SOME INFO TAKEN FROM # ==================== # http://blog.flaphead.dns2go.com/archive/2009/07/29/system-uptime.aspx # # DISCLAIMER # ========== # THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE # RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER. ############################################################################# if (-not((Get-PSSnapin) -match "Microsoft.Exchange.Management.PowerShell.E2010")){ Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 } $strScriptName = $MyInvocation.MyCommand.Name if (!(Get-ItemProperty HKLM:\Software\Innervation\$strScriptName -Name LastRun -EA SilentlyContinue)){ # this is the first time the script has run - let's create the registry key and value for future runs New-Item -path HKLM:\Software\Innervation -EA SilentlyContinue | Out-Null New-Item -path HKLM:\Software\Innervation\$strScriptName | Out-Null New-ItemProperty -path HKLM:\Software\Innervation\$strScriptName -Name "LastRun" -Value (Get-Date) -propertyType String | Out-Null write-host "Initial configuration completed." -ForegroundColor green } # get time stamp from registry so we know when it last ran $LastRun = Get-Date ((Get-ItemProperty -path HKLM:\Software\Innervation\$strScriptName -Name LastRun).LastRun) $ElapsedTime = ((Get-Date) - $lastrun).TotalSeconds # Let's define some variables that we'll use throughout the process. $strMsgFrom = "<htsiddiqui@pern.edu.pk>" $strMsgTitle = "Welcome to Edudcational Alliance Messaging System" # These set the From and Title for the email that we'll send, as well as get today's date, and the name of the script. Next, we create a new object to allow sending SMTP email: $SMTPClient = New-Object Net.Mail.SmtpClient("10.110.0.86") # We can replace "localhost" with the IP address of a remote hub transport server if the script is not running on a hub transport server. # Next, we get a list of mailboxes that we need to send the email to. We'll use a scheduled task to actually run the task. I run mine every 4 hours, but the code doesn't care how often it runs. It will use the time stamp established above to email all mailbox created since then. We also want to avoid any mailboxes that are disabled. So our query looks like this: $MBXArray = @(Get-Mailbox -ResultSize Unlimited | ? {($_.WhenCreated -gt (Get-Date).AddSeconds(-$ElapsedTime)) -and ($_.ExchangeUserAccountControl -ne "AccountDisabled")}) # We now have an array, $MBXArray, that contains all of the mailboxes that we'll email. We now cycle through the array via ForEach, and begin to assemble a personalized email message to each user. $mailbox holds the current account in the loop, so we can pull specific info for each user. Note that the text in $strBody is completely arbitrary - you can include whatever you want. Here's a sample of one I did for a recent client: ForEach ($mailbox in $MBXArray ) { $strMsgTo = $mailbox.PrimarySMTPAddress $strMsgBody = "Hello, "+$mailbox.DisplayName+", and welcome to the Educational Alliance Messaging System! Please keep this email for future use. It contains vital information. -------------------------------------- Username and password -------------------------------------- Your network username is '"+$mailbox.SamAccountName+"'. Use your username and password to login to the network. Your password should NEVER be shared with anyone except the I.T. department, and only then when requested. Please do not write it down on anything that can be seen by your coworkers. You will be prompted to change it regularly. -------------------------------------- Email -------------------------------------- Your email address is '"+$mailbox.PrimarySMTPAddress+"'. To access your email, calendar, contacts, and tasks from outside of the building, such as from home, you can do so from any Internet connected computer. Simply open Internet Explorer and go to the Outlook Web Access (OWA) page at https://mail.pern.edu.pk/owa and log in using your username and password. Please note the 's' in https. Thank you, and, again, welcome to HEC Education Alliance Messaging System! The Information Technology Department" # As you can see, we insert the user's actual account name, email address, etc since that info is available in the ForEach loop. The message is just plain text, so spacing is preserved. URLs will be clickable links as well. Note: You'll want to pay close attention to quotes and variables, as having an extra or missing quote can cause an error. # Now we actually send the message: $SMTPClient.Send($strMsgFrom,$strMsgTo,$strMsgTitle,$strMsgBody) } # update registry here with a fresh time stamp Set-ItemProperty HKLM:\Software\Innervation\$strScriptName -Name "LastRun" -Value (Get-Date) | Out-Null Hasan
April 9th, 2011 2:28am

On Sat, 9 Apr 2011 06:22:31 +0000, Hasan-Exchanger wrote: > > >Hello, > >I am trying to run script for creating welcome email message to new user. The script is running fine, but i am not receiving any welcome email. THere is no error in script but i am not getting email even after creating new mailbox. Here is the script. Please help how to diagnose whether email is going or not.......... Is 10.110.0.86 the IP address of your HT server? Do you see connections in your SMTP protocol log from whatever machine it is that you're using to run the script? --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
April 9th, 2011 10:41pm

On Sat, 9 Apr 2011 06:22:31 +0000, Hasan-Exchanger wrote: > > >Hello, > >I am trying to run script for creating welcome email message to new user. The script is running fine, but i am not receiving any welcome email. THere is no error in script but i am not getting email even after creating new mailbox. Here is the script. Please help how to diagnose whether email is going or not.......... Is 10.110.0.86 the IP address of your HT server? Do you see connections in your SMTP protocol log from whatever machine it is that you're using to run the script? --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP Yes, 10.110.0.86 is my HT server.And i m running script on same server. I cannot see any activity in my connectivity log, smtp send/receive log is empty and connectivity log is also empty..........also i have made receive connector on same machine with anonymous access, even i have put HT IP in allowed connection list. Hasan
April 10th, 2011 4:52am

I suggest you seperate your script to two parts and then test if each works good. First you can output the element of the mailbox array $MBXArray you defined, see if there is the mail address you just create, if not, I think you'd better check the $ElapsedTime parameter, you can define a const string to test; second you can test if your sending mail part works good. If both of them work good, I think your script should work.Nile Jiang- Please mark the post as answer if it answers your question. http://www.usefulshare.com
Free Windows Admin Tool Kit Click here and download it now
April 10th, 2011 7:11am

On Sun, 10 Apr 2011 08:46:28 +0000, Hasan-Exchanger wrote: >On Sat, 9 Apr 2011 06:22:31 +0000, Hasan-Exchanger wrote: > > >Hello, > >I am trying to run script for creating welcome email message to new user. The script is running fine, but i am not receiving any welcome email. THere is no error in script but i am not getting email even after creating new mailbox. Here is the script. Please help how to diagnose whether email is going or not.......... Is 10.110.0.86 the IP address of your HT server? Do you see connections in your SMTP protocol log from whatever machine it is that you're using to run the script? --- Rich Matheisen MCSE+I, Exchange MVP >--- Rich Matheisen MCSE+I, Exchange MVPYes, 10.110.0.86 is my HT server.And i m running script on same server. I cannot see any activity in my connectivity log, smtp send/receive log is empty and connectivity log is also empty..........also i have made receive connector on same machine with anonymous access, even i have put HT IP in allowed connection list. Does this work? $SMTPClient = New-Object System.Net.Mail.SmtpClient("10.110.0.86") $mail = New-Object System.Net.Mail.MailMessage $from = New-Object System.Net.Mail.MailAddress("youraddress@domain.com") $to = New-Object System.Net.Mail.MailAddress("someaddress@yourdomain.com") $msg = "This is a test" $sub = "This is the test subject" $mail.from = $from $mail.to.add($to) $mail.subject = $sub $mail.body = $msg $SMTPClient.Send($mail) --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
April 10th, 2011 12:48pm

On Sun, 10 Apr 2011 08:46:28 +0000, Hasan-Exchanger wrote: >On Sat, 9 Apr 2011 06:22:31 +0000, Hasan-Exchanger wrote: > > >Hello, > >I am trying to run script for creating welcome email message to new user. The script is running fine, but i am not receiving any welcome email. THere is no error in script but i am not getting email even after creating new mailbox. Here is the script. Please help how to diagnose whether email is going or not.......... Is 10.110.0.86 the IP address of your HT server? Do you see connections in your SMTP protocol log from whatever machine it is that you're using to run the script? --- Rich Matheisen MCSE+I, Exchange MVP >--- Rich Matheisen MCSE+I, Exchange MVPYes, 10.110.0.86 is my HT server.And i m running script on same server. I cannot see any activity in my connectivity log, smtp send/receive log is empty and connectivity log is also empty..........also i have made receive connector on same machine with anonymous access, even i have put HT IP in allowed connection list. Does this work? $SMTPClient = New-Object System.Net.Mail.SmtpClient("10.110.0.86") $mail = New-Object System.Net.Mail.MailMessage $from = New-Object System.Net.Mail.MailAddress("youraddress@domain.com") $to = New-Object System.Net.Mail.MailAddress("someaddress@yourdomain.com") $msg = "This is a test" $sub = "This is the test subject" $mail.from = $from $mail.to.add($to) $mail.subject = $sub $mail.body = $msg $SMTPClient.Send($mail) --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP It is asking for TYPE.......what is this??? I have changed the script to this if (-not((Get-PSSnapin) -match "Microsoft.Exchange.Management.PowerShell.E2010")){ Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 } $strScriptName = $MyInvocation.MyCommand.Name if (!(Get-ItemProperty HKLM:\Software\Innervation\$strScriptName -Name LastRun -EA SilentlyContinue)){ # this is the first time the script has run - let's create the registry key and value for future runs New-Item -path HKLM:\Software\Innervation -EA SilentlyContinue | Out-Null New-Item -path HKLM:\Software\Innervation\$strScriptName | Out-Null New-ItemProperty -path HKLM:\Software\Innervation\$strScriptName -Name "LastRun" -Value (Get-Date) -propertyType String | Out-Null write-host "Initial configuration completed." -ForegroundColor green } $SMTPClient = New-Object System.Net.Mail.SmtpClient("10.110.0.86") $mail = New-Object System.Net.Mail.MailMessage $from = New-Object System.Net.Mail.MailAddress("htsiddiqui@hec.gov.pk") $to = New-Object System.Net.Mail.MailAddress("htsid5@hotmail.com") $msg = "This is a test" $sub = "This is the test subject" $mail.from = $from $mail.to.add($to) $mail.subject = $sub $mail.body = $msg $SMTPClient.Send($mail) cmdlet New-Object at command pipeline position 1 Supply values for the following parameters: TypeName: Hasan
Free Windows Admin Tool Kit Click here and download it now
April 10th, 2011 11:45pm

On Sun, 10 Apr 2011 08:46:28 +0000, Hasan-Exchanger wrote: >On Sat, 9 Apr 2011 06:22:31 +0000, Hasan-Exchanger wrote: > > >Hello, > >I am trying to run script for creating welcome email message to new user. The script is running fine, but i am not receiving any welcome email. THere is no error in script but i am not getting email even after creating new mailbox. Here is the script. Please help how to diagnose whether email is going or not.......... Is 10.110.0.86 the IP address of your HT server? Do you see connections in your SMTP protocol log from whatever machine it is that you're using to run the script? --- Rich Matheisen MCSE+I, Exchange MVP >--- Rich Matheisen MCSE+I, Exchange MVPYes, 10.110.0.86 is my HT server.And i m running script on same server. I cannot see any activity in my connectivity log, smtp send/receive log is empty and connectivity log is also empty..........also i have made receive connector on same machine with anonymous access, even i have put HT IP in allowed connection list. Does this work? $SMTPClient = New-Object System.Net.Mail.SmtpClient("10.110.0.86") $mail = New-Object System.Net.Mail.MailMessage $from = New-Object System.Net.Mail.MailAddress("youraddress@domain.com") $to = New-Object System.Net.Mail.MailAddress("someaddress@yourdomain.com") $msg = "This is a test" $sub = "This is the test subject" $mail.from = $from $mail.to.add($to) $mail.subject = $sub $mail.body = $msg $SMTPClient.Send($mail) --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP It is asking for TYPE.......what is this??? I have changed the script to this if (-not((Get-PSSnapin) -match "Microsoft.Exchange.Management.PowerShell.E2010")){ Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 } $strScriptName = $MyInvocation.MyCommand.Name if (!(Get-ItemProperty HKLM:\Software\Innervation\$strScriptName -Name LastRun -EA SilentlyContinue)){ # this is the first time the script has run - let's create the registry key and value for future runs New-Item -path HKLM:\Software\Innervation -EA SilentlyContinue | Out-Null New-Item -path HKLM:\Software\Innervation\$strScriptName | Out-Null New-ItemProperty -path HKLM:\Software\Innervation\$strScriptName -Name "LastRun" -Value (Get-Date) -propertyType String | Out-Null write-host "Initial configuration completed." -ForegroundColor green } $SMTPClient = New-Object System.Net.Mail.SmtpClient("10.110.0.86") $mail = New-Object System.Net.Mail.MailMessage $from = New-Object System.Net.Mail.MailAddress("htsiddiqui@abc,com") $to = New-Object System.Net.Mail.MailAddress("htsid5@hotmail.com") $msg = "This is a test" $sub = "This is the test subject" $mail.from = $from $mail.to.add($to) $mail.subject = $sub $mail.body = $msg $SMTPClient.Send($mail) cmdlet New-Object at command pipeline position 1 Supply values for the following parameters: TypeName: Hasan
April 10th, 2011 11:46pm

I suggest you seperate your script to two parts and then test if each works good. First you can output the element of the mailbox array $MBXArray you defined, see if there is the mail address you just create, if not, I think you'd better check the $ElapsedTime parameter, you can define a const string to test; second you can test if your sending mail part works good. If both of them work good, I think your script should work. Nile Jiang- Please mark the post as answer if it answers your question. http://www.usefulshare.com Nile, i am not good in scripting.............can you please separate the script for me???Hasan
Free Windows Admin Tool Kit Click here and download it now
April 10th, 2011 11:47pm

On Mon, 11 Apr 2011 03:44:25 +0000, Hasan-Exchanger wrote: [ snip ] >It is asking for TYPE.......what is this??? If you've put the cmdlet on one line and the type on another it isn't going to work unless you put a "space backtick" at the end of the 1st line" This: $from = New-Object System.Net.Mail.MailAddress("htsiddiqui@hec.gov.pk") Should be all on one line. Or it should look like this: $from = New-Object ` System.Net.Mail.MailAddress("htsiddiqui@hec.gov.pk") Every cmdlet in the little bit of code I gave you should be on a single line. That's the problem with posting stuff in these forums. Line-wrapping and HTML space suppression make things hasrd to format. --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
April 11th, 2011 12:05am

On Mon, 11 Apr 2011 03:44:25 +0000, Hasan-Exchanger wrote: [ snip ] >It is asking for TYPE.......what is this??? If you've put the cmdlet on one line and the type on another it isn't going to work unless you put a "space backtick" at the end of the 1st line" This: $from = New-Object System.Net.Mail.MailAddress("htsiddiqui@abc.com") Should be all on one line. Or it should look like this: $from = New-Object ` System.Net.Mail.MailAddress("htsiddiqui@abc.com") Every cmdlet in the little bit of code I gave you should be on a single line. That's the problem with posting stuff in these forums. Line-wrapping and HTML space suppression make things hasrd to format. --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP Rich, i got the mail. Now what's next??? Hasan
Free Windows Admin Tool Kit Click here and download it now
April 11th, 2011 12:45am

On Mon, 11 Apr 2011 04:43:17 +0000, Hasan-Exchanger wrote: >On Mon, 11 Apr 2011 03:44:25 +0000, Hasan-Exchanger wrote: [ snip ] >It is asking for TYPE.......what is this??? If you've put the cmdlet on one line and the type on another it isn't going to work unless you put a "space backtick" at the end of the 1st line" This: $from = New-Object System.Net.Mail.MailAddress("htsiddiqui@abc.com") Should be all on one line. Or it should look like this: $from = New-Object ` System.Net.Mail.MailAddress("htsiddiqui@abc.com") Every cmdlet in the little bit of code I gave you should be on a single line. That's the problem with posting stuff in these forums. Line-wrapping and HTML space suppression make things hasrd to format. --- Rich Matheisen MCSE+I, Exchange MVP >--- Rich Matheisen MCSE+I, Exchange MVPRich, i got the mail. Now what's next??? Try replacing the line: $strMsgTo = $mailbox.PrimarySMTPAddress with: $strMsgTo = $mailbox.PrimarySMTPAddress.tostring() The Send method wants four strings and the value in $strMsgTo isn't a string, it's an object with four properties. http://msdn.microsoft.com/en-us/library/h1s04he7.aspx --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
April 11th, 2011 9:32pm

On Mon, 11 Apr 2011 04:43:17 +0000, Hasan-Exchanger wrote: >On Mon, 11 Apr 2011 03:44:25 +0000, Hasan-Exchanger wrote: [ snip ] >It is asking for TYPE.......what is this??? If you've put the cmdlet on one line and the type on another it isn't going to work unless you put a "space backtick" at the end of the 1st line" This: $from = New-Object System.Net.Mail.MailAddress("htsiddiqui@abc.com") Should be all on one line. Or it should look like this: $from = New-Object ` System.Net.Mail.MailAddress("htsiddiqui@abc.com") Every cmdlet in the little bit of code I gave you should be on a single line. That's the problem with posting stuff in these forums. Line-wrapping and HTML space suppression make things hasrd to format. --- Rich Matheisen MCSE+I, Exchange MVP >--- Rich Matheisen MCSE+I, Exchange MVPRich, i got the mail. Now what's next??? Try replacing the line: $strMsgTo = $mailbox.PrimarySMTPAddress with: $strMsgTo = $mailbox.PrimarySMTPAddress.tostring() The Send method wants four strings and the value in $strMsgTo isn't a string, it's an object with four properties. http://msdn.microsoft.com/en-us/library/h1s04he7.aspx --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP Wow.........that works Rich.........you rock man once again :) I want to ask one more thing. It is sending email to newly created users, i mean i created 1 user yesterday and it has send him email, but accounts created 2-3 days before mail is not send to them. What to do if i want to send email to already created users few days back? And on what mechanism this script working. I mean how it is judging that this user is newly created, on whcih line so i can try to play with that............. Also i want to schedule it to run all the time, i dont want users to wait for welcome email. As soon as i create email account for the user, mail should be generated immediately. i.e. when i create email account email shoudl be delivered to welcome new user. just like in Gmail when you create new acount and visit inbox there are 3 mails arleady to welcome you. i want same thing...... Hasan
Free Windows Admin Tool Kit Click here and download it now
April 12th, 2011 12:04am

On Mon, 11 Apr 2011 04:43:17 +0000, Hasan-Exchanger wrote: >On Mon, 11 Apr 2011 03:44:25 +0000, Hasan-Exchanger wrote: [ snip ] >It is asking for TYPE.......what is this??? If you've put the cmdlet on one line and the type on another it isn't going to work unless you put a "space backtick" at the end of the 1st line" This: $from = New-Object System.Net.Mail.MailAddress("htsiddiqui@abc.com") Should be all on one line. Or it should look like this: $from = New-Object ` System.Net.Mail.MailAddress("htsiddiqui@abc.com") Every cmdlet in the little bit of code I gave you should be on a single line. That's the problem with posting stuff in these forums. Line-wrapping and HTML space suppression make things hasrd to format. --- Rich Matheisen MCSE+I, Exchange MVP >--- Rich Matheisen MCSE+I, Exchange MVPRich, i got the mail. Now what's next??? Try replacing the line: $strMsgTo = $mailbox.PrimarySMTPAddress with: $strMsgTo = $mailbox.PrimarySMTPAddress.tostring() The Send method wants four strings and the value in $strMsgTo isn't a string, it's an object with four properties. http://msdn.microsoft.com/en-us/library/h1s04he7.aspx --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP Wow.........that works Rich.........you rock man once again :) I want to ask one more thing. It is sending email to newly created users, i mean i created 1 user yesterday and it has send him email, but accounts created 2-3 days before mail is not send to them. What to do if i want to send email to already created users few days back? And on what mechanism this script working. I mean how it is judging that this user is newly created, on whcih line so i can try to play with that............. Also i want to schedule it to run after every 5 minutes. Hasan
April 12th, 2011 12:04am

On Tue, 12 Apr 2011 04:02:15 +0000, Hasan-Exchanger wrote: >On Mon, 11 Apr 2011 04:43:17 +0000, Hasan-Exchanger wrote: >On Mon, 11 Apr 2011 03:44:25 +0000, Hasan-Exchanger wrote: [ snip ] >It is asking for TYPE.......what is this??? If you've put the cmdlet on one line and the type on another it isn't going to work unless you put a "space backtick" at the end of the 1st line" This: $from = New-Object System.Net.Mail.MailAddress("htsiddiqui@abc.com") Should be all on one line. Or it should look like this: $from = New-Object ` System.Net.Mail.MailAddress("htsiddiqui@abc.com") Every cmdlet in the little bit of code I gave you should be on a single line. That's the problem with posting stuff in these forums. Line-wrapping and HTML space suppression make things hasrd to format. --- Rich Matheisen MCSE+I, Exchange MVP >--- Rich Matheisen MCSE+I, Exchange MVPRich, i got the mail. Now what's next??? Try replacing the line: $strMsgTo = $mailbox.PrimarySMTPAddress with: $strMsgTo = $mailbox.PrimarySMTPAddress.tostring() The Send method >wants four strings and the value in $strMsgTo isn't a string, it's an object with four properties. http://msdn.microsoft.com/en-us/library/h1s04he7.aspx --- Rich Matheisen MCSE+I, Exchange MVP >--- Rich Matheisen MCSE+I, Exchange MVP > >Wow.........that works Rich.........you rock man once again :) > >I want to ask one more thing. It is sending email to newly created users, i mean i created 1 user yesterday and it has send him email, but accounts created 2-3 days before mail is not send to them. It will only send an e-mail to accounts with a "When-Created" date that's more recent than the value in the registry the script creates (or modifies) when it runs. If you want to back-date that time then fo anead and modify the value in the registry. >What to do if i want to send email to already created users few days back? And on what mechanism this script working. I mean how it is judging that this user is newly created, on whcih line so i can try to play with that............. > >Also i want to schedule it to run all the time, i dont want users to wait for welcome email. As soon as i create email account for the user, mail should be generated immediately. i.e. when i create email account email shoudl be delivered to welcome new user. just like in Gmail when you create new acount and visit inbox there are 3 mails arleady to welcome you. i want same thing...... Then create users with a script and incorporate the code you posted as part of that script. --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
April 12th, 2011 8:01pm

On Tue, 12 Apr 2011 04:02:15 +0000, Hasan-Exchanger wrote: >On Mon, 11 Apr 2011 04:43:17 +0000, Hasan-Exchanger wrote: >On Mon, 11 Apr 2011 03:44:25 +0000, Hasan-Exchanger wrote: [ snip ] >It is asking for TYPE.......what is this??? If you've put the cmdlet on one line and the type on another it isn't going to work unless you put a "space backtick" at the end of the 1st line" This: $from = New-Object System.Net.Mail.MailAddress("htsiddiqui@abc.com") Should be all on one line. Or it should look like this: $from = New-Object ` System.Net.Mail.MailAddress("htsiddiqui@abc.com") Every cmdlet in the little bit of code I gave you should be on a single line. That's the problem with posting stuff in these forums. Line-wrapping and HTML space suppression make things hasrd to format. --- Rich Matheisen MCSE+I, Exchange MVP >--- Rich Matheisen MCSE+I, Exchange MVPRich, i got the mail. Now what's next??? Try replacing the line: $strMsgTo = $mailbox.PrimarySMTPAddress with: $strMsgTo = $mailbox.PrimarySMTPAddress.tostring() The Send method >wants four strings and the value in $strMsgTo isn't a string, it's an object with four properties. http://msdn.microsoft.com/en-us/library/h1s04he7.aspx --- Rich Matheisen MCSE+I, Exchange MVP >--- Rich Matheisen MCSE+I, Exchange MVP > >Wow.........that works Rich.........you rock man once again :) > >I want to ask one more thing. It is sending email to newly created users, i mean i created 1 user yesterday and it has send him email, but accounts created 2-3 days before mail is not send to them. It will only send an e-mail to accounts with a "When-Created" date that's more recent than the value in the registry the script creates (or modifies) when it runs. If you want to back-date that time then fo anead and modify the value in the registry. >What to do if i want to send email to already created users few days back? And on what mechanism this script working. I mean how it is judging that this user is newly created, on whcih line so i can try to play with that............. > >Also i want to schedule it to run all the time, i dont want users to wait for welcome email. As soon as i create email account for the user, mail should be generated immediately. i.e. when i create email account email shoudl be delivered to welcome new user. just like in Gmail when you create new acount and visit inbox there are 3 mails arleady to welcome you. i want same thing...... Then create users with a script and incorporate the code you posted as part of that script. --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP Ok i have scripts to make new users in bulk through CSV. So in the end of the script, which part of my welcome message code should i insert in the end of user creation code. Please be informed that i have code for creating USER accounts in AD. Then with the hlep of single CMDlet i can enable mailboxes. So how could i embed that cmdlet into welcome message code. THe cmdlet is get-user –organizationalUnit USTB | where-object {$_.RecipientType –eq “User” } | Enable-Mailbox –Database USTB | get-mailbox | select name,windowsemailaddress,database,alias Can i incorporate this command into my shell script??? if yes then how? I am really unable to understand the timing thing. Please elaborate me this part of script...........why it is not instantly allowing me to send welcome email. if (-not((Get-PSSnapin) -match "Microsoft.Exchange.Management.PowerShell.E2010")){ Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 } $strScriptName = $MyInvocation.MyCommand.Name if (!(Get-ItemProperty HKLM:\Software\Innervation\$strScriptName -Name LastRun -EA SilentlyContinue)){ # this is the first time the script has run - let's create the registry key and value for future runs New-Item -path HKLM:\Software\Innervation -EA SilentlyContinue | Out-Null New-Item -path HKLM:\Software\Innervation\$strScriptName | Out-Null New-ItemProperty -path HKLM:\Software\Innervation\$strScriptName -Name "LastRun" -Value (Get-Date) -propertyType String | Out-Null write-host "Initial configuration completed." -ForegroundColor green } # get time stamp from registry so we know when it last ran $LastRun = Get-Date ((Get-ItemProperty -path HKLM:\Software\Innervation\$strScriptName -Name LastRun).LastRun) $ElapsedTime = ((Get-Date) - $lastrun).TotalSeconds Hasan
April 13th, 2011 3:06am

On Tue, 12 Apr 2011 04:02:15 +0000, Hasan-Exchanger wrote: >On Mon, 11 Apr 2011 04:43:17 +0000, Hasan-Exchanger wrote: >On Mon, 11 Apr 2011 03:44:25 +0000, Hasan-Exchanger wrote: [ snip ] >It is asking for TYPE.......what is this??? If you've put the cmdlet on one line and the type on another it isn't going to work unless you put a "space backtick" at the end of the 1st line" This: $from = New-Object System.Net.Mail.MailAddress("htsiddiqui@abc.com") Should be all on one line. Or it should look like this: $from = New-Object ` System.Net.Mail.MailAddress("htsiddiqui@abc.com") Every cmdlet in the little bit of code I gave you should be on a single line. That's the problem with posting stuff in these forums. Line-wrapping and HTML space suppression make things hasrd to format. --- Rich Matheisen MCSE+I, Exchange MVP >--- Rich Matheisen MCSE+I, Exchange MVPRich, i got the mail. Now what's next??? Try replacing the line: $strMsgTo = $mailbox.PrimarySMTPAddress with: $strMsgTo = $mailbox.PrimarySMTPAddress.tostring() The Send method >wants four strings and the value in $strMsgTo isn't a string, it's an object with four properties. http://msdn.microsoft.com/en-us/library/h1s04he7.aspx --- Rich Matheisen MCSE+I, Exchange MVP >--- Rich Matheisen MCSE+I, Exchange MVP > >Wow.........that works Rich.........you rock man once again :) > >I want to ask one more thing. It is sending email to newly created users, i mean i created 1 user yesterday and it has send him email, but accounts created 2-3 days before mail is not send to them. It will only send an e-mail to accounts with a "When-Created" date that's more recent than the value in the registry the script creates (or modifies) when it runs. If you want to back-date that time then fo anead and modify the value in the registry. >What to do if i want to send email to already created users few days back? And on what mechanism this script working. I mean how it is judging that this user is newly created, on whcih line so i can try to play with that............. > >Also i want to schedule it to run all the time, i dont want users to wait for welcome email. As soon as i create email account for the user, mail should be generated immediately. i.e. when i create email account email shoudl be delivered to welcome new user. just like in Gmail when you create new acount and visit inbox there are 3 mails arleady to welcome you. i want same thing...... Then create users with a script and incorporate the code you posted as part of that script. --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP Ok i have scripts to make new users in bulk through CSV. So in the end of the script, which part of my welcome message code should i insert in the end of user creation code. Please be informed that i have code for creating USER accounts in AD. Then with the hlep of single CMDlet i can enable mailboxes. So how could i embed that cmdlet into welcome message code. THe cmdlet is get-user –organizationalUnit USTB | where-object {$_.RecipientType –eq “User” } | Enable-Mailbox –Database USTB | get-mailbox | select name,windowsemailaddress,database,alias Can i incorporate this command into my shell script??? if yes then how? Hasan
Free Windows Admin Tool Kit Click here and download it now
April 13th, 2011 3:06am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics