Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Get All mailboxes in Entire Forest script Help required

$
0
0

Hello Powershell experts,

I am not a expert and fairly new to the powershell and I need some assistance on my below script. If I run the below script on a exchange 2007 shell it works and sends the email with the attachment.

However when I schedule this script it doesn't work and telling me that viewentireforest could not be found and also it does not do the job but I am still receiving email with no attachment. Please note that adding the line viewentireforest is because I have various child domain as well.

Also What I wanted that once this scripts completed the task then it delete the output file after I received the email.

So I will be very thankful to you if you can help me on this script please. Its very important for me so quick response will be highly appreciated.

ADD-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
$adminsessionadsettings.viewentireforest = $true
Get-mailbox -identity alihussaini | Select DisplayName,Alias,RecipientType,PrimarySmtpAddress,Database,OrganizationalUnit | Export-csv AllMailboxes.csv

$From = “abc@domain.com
$To = abc@domain.com”
$Subject = “All Mailbox in the Environment” 
$Server = “smtpserver”
$emailattachment = "C:\Script\Allmailboxes.csv"

$mailmessage = New-Object system.net.mail.mailmessage $from,$to,$subject,$attachement

$attachment = New-Object System.Net.Mail.Attachment $emailattachment
$mailmessage.Attachments.Add($attachment)

$SMTPClient = New-Object system.Net.Mail.SmtpClient $Server 
$SMTPClient.Send($mailmessage)

On schedule task I am setting the task like this.

Action: Start a Programe

Settings: Program/Script: Powershell.exe

Add Arguments: - Command "C:\scripts\Get-Allmailboxes.ps1


Ali Hussaini


Viewing all articles
Browse latest Browse all 21975

Trending Articles