Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've written a script that intends to retrieve the DatabaseSize of a database from Exchange 2010. I created a new AD user for this script to run under as a scheduled task. I gave this user admin rights to the Exchange Organization (as a last resort during my testing) and local admin rights on the Exchange machine.

When I run this script manually by starting powershell (with runas /noprofile /user:domain\user powershell) everything works fine. All the database properties are available. When I run the script as a scheduled task a lot of the properties are null including the one I want: DatabaseSize.

I've also tried running the script as the domain admin account with the same results.

There must be something different in the two contexts but I can't figure out what it is.

My script:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

Write-EventLog 'Windows PowerShell' -source PowerShell -eventid 100 -message "Starting script"

$databases = get-mailboxdatabase -status

if($databases -ne $null)
{
    Write-EventLog 'Windows PowerShell' -source PowerShell -eventid 100 -message "Object created"

    $databasesize_text = $databases.databasesize.tomb().tostring()

    if($databasesize_text -ne $null)
    {
        $output = "echo "+$databasesize_text+":ok"

        Write-EventLog 'Windows PowerShell' -source PowerShell -eventid 100 -message "Path check"

        if(test-path "\\mon-01\prtgsensors\EXE\")
        {
            Write-EventLog 'Windows PowerShell' -source PowerShell -eventid 100 -message "Path valid"
            Set-Content \\mon-01\prtgsensors\EXE\ex-05_db_size.bat -value $output
        }

        Write-EventLog 'Windows PowerShell' -source PowerShell -eventid 100 -message "Exiting program"
    }
    else
    {
        Write-EventLog 'Windows PowerShell' -source PowerShell -eventid 100 -message "databasesize_text is empty. nothing to do"
    }
}
else
{
    Write-EventLog 'Windows PowerShell' -source PowerShell -eventid 100 -message "object not created. nothing to do"
}

exit 0
share|improve this question
    
Are you running this externally (using a remote powershell)? I've noticed that the .toMB doesn't work when running a remote shell, but it does if you run it directly on an exchange server. Frustrating issue. –  user94533 Sep 13 '11 at 9:06
add comment

1 Answer

up vote 0 down vote accepted

Did you create a "Basic Task" or a "New Task"? You can set the security options for your task if you use "New Task" directly on the first page of the dialog.

share|improve this answer
    
Additionally, you might experience a bug, which can be resolved by a workaround using XML import/export. See social.technet.microsoft.com/Forums/en-US/winserverManagement/… –  Christoph Jan 13 '11 at 21:14
1  
I had already created it using New Task and tried different variations of checking/unchecking the "Run with highest privileges" option but had never tried changing the "Configure for:" option to 2008 R2. It was set to 2008/Vista previously. –  barophobia Jan 13 '11 at 21:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.