Вопрос

I've wrote a script that reads all mail from an Exchange inbox and writes all sort of output (.txt files, folders, ..). Everything is working fine when I run this in the powershell ISE. The problem starts when I make a bat (powershell.exe C:\script.ps1) and schedule the bat in TaskManager. All folders are created, output files are created but they are empty. Normally, the content of a Global Variable goes into the file, but now it doesn't..

## Global ###
$body = ''
$dateReceived = ''
$attachCont = ''

Function check() {
    DoSomething
    $Global:body = $mail.body.text
}

Function Write() {
    $body >> 'file.txt'
}

I'm doing something like this (look above). 'File.txt' is made, but it's empty. When I do a 'Write-Host $body' just above writing the file, I see nothing. So there is something wrong with the global variable (I think?). NOTE: When I run it in the ISE, the content is written, when I start the task in Task manager, the content ISN'T written.

Is this a permission problem/a global variable problem?

Это было полезно?

Решение

Got it. When I don't define the Global variables first, it works like a charm.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top