JuusoConnecta
asked on
Powershell, Scheduled Task, Exchange
Hello Experts,
I have a somewhat bizarre problem which I cant figure out. I have a windows 2008 server r2, which acts as a script runner. In other words it's only purpose is to run scheduled scripts.
Everything and all of the scripts works fine, except one of the scripts. This script bulks out mailbox end user information from exchange 2003 and outputes it to a csv file.
My problem:
When I run the script manually I get all the headers + information out in the csv file
When the script is run from scheduled tasks, it does not output all the information required.
Script code:
$Date = Get-Date
$Date = $Date.ToString("ddMMyyyy")
Get-WmiObject -Class Exchange_Mailbox -NameSpace root\microsoftexchangev2 -ComputerName ExchangeServerName1,Exchan geServerNa me2 | where {$_.DateDiscoveredAbsentIn DS -eq $null} | select @{Label='SamAccountName';E xpression= {(Get-QADU ser -Identity $_.LegacyDN).SamAccountNam e}}, @{Label='mail';Expression= {(Get-QADU ser -includedproperties "mail" -Identity $_.LegacyDN).mail}}, ServerName, StorageGroupName, Storename, Size, mailboxdisplayname | Export-Csv C:\Management\MailboxUserI nfo\Exchan ge2003MUI$ date.csv -NoTypeInformation
When i run the script manually heres what the output looks like:
SamAccountName,"mail","Ser verName"," StorageGro upName","S torename", "Size","ma ilboxdispl ayname"
Firma,"Firstname.Lastname@ domain.se" ,"SMCR090V ","First Storage Group","Std2","184319","Fu llName"
EM0403,"Firstname.Lastname @domain.se ","SMCR090 V","First Storage Group","Std2","567","FullN ame"
But when ran from scheduled tasks, the output looks like this:
SamAccountName,"mail","Ser verName"," StorageGro upName","S torename", "Size","ma ilboxdispl ayname"
,,"SMCR090V","First Storage Group","Std2","184319","Fu llname"
,,"SMCR090V","First Storage Group","Std2","567","Fulln ame"
Conclusion:
As you can see when the script is ran from scheduled tasks it will not output the SamAccountName and Mail... Any ideas experts ?
cheer,s
//Juuso
I have a somewhat bizarre problem which I cant figure out. I have a windows 2008 server r2, which acts as a script runner. In other words it's only purpose is to run scheduled scripts.
Everything and all of the scripts works fine, except one of the scripts. This script bulks out mailbox end user information from exchange 2003 and outputes it to a csv file.
My problem:
When I run the script manually I get all the headers + information out in the csv file
When the script is run from scheduled tasks, it does not output all the information required.
Script code:
$Date = Get-Date
$Date = $Date.ToString("ddMMyyyy")
Get-WmiObject -Class Exchange_Mailbox -NameSpace root\microsoftexchangev2 -ComputerName ExchangeServerName1,Exchan
When i run the script manually heres what the output looks like:
SamAccountName,"mail","Ser
Firma,"Firstname.Lastname@
EM0403,"Firstname.Lastname
But when ran from scheduled tasks, the output looks like this:
SamAccountName,"mail","Ser
,,"SMCR090V","First Storage Group","Std2","184319","Fu
,,"SMCR090V","First Storage Group","Std2","567","Fulln
Conclusion:
As you can see when the script is ran from scheduled tasks it will not output the SamAccountName and Mail... Any ideas experts ?
cheer,s
//Juuso
in the Schedule task have you entered the username and password with account that you running manually? it may be the permissions issue.
ASKER
Thanks for the input. I've taken that into consideration and the result is the same.
I have scheduled the script to be run with the same user account and password than when I run it manually..
I have scheduled the script to be run with the same user account and password than when I run it manually..
Have you set script to run with highest privileges?
ASKER
Yes
how did you schedule the script? In a batch file?
ASKER
No, its directly a powershell script.
Program script: C:\Windows\System32\Window sPowerShel l\v1.0\pow ershell.ex e
Add argument: C:\Management\Scripts\Work ingScripts \Exchange2 003UserInf o.ps1
Program script: C:\Windows\System32\Window
Add argument: C:\Management\Scripts\Work
can you check below post and see if this can be the reason
http://www.jamssupport.com/KnowledgebaseArticle50027.aspx
http://www.jamssupport.com/KnowledgebaseArticle50027.aspx
ASKER
Have tried that as well, that isnt the issue. The script is fully functional when running it manually, but not when running thru scheduled tasks, regardless if you use the parameter set-executionpolicy.
I can also add that all other scripts, for example a script that basically does the same thing runs against Exchange 2010 works perfectly, but not the one that goes against exchange 2003..
regards
I can also add that all other scripts, for example a script that basically does the same thing runs against Exchange 2010 works perfectly, but not the one that goes against exchange 2003..
regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did you issue exact the same commandline? Get-QADUser is Quest cmdlet not loaded as part of the default modules. Your command for testing it manually should say
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\Management\Scripts\WorkingScripts\Exchange2003UserInfo.ps1
, started in e.g. a Cmd window.
ASKER
Cheers slidingfox, been working so many scripts lately in the same powershell session (probably havent closed it for 3 weeks), so I did not even notice that the quest modules were already in the session, of course I didnt have the add-pssnapin parameter in the scheduled script...
Thanks for this, it was the last of my 10 scripts =), can now relax with a good conscious. Cheers!
Thanks for this, it was the last of my 10 scripts =), can now relax with a good conscious. Cheers!