Profile temp folder and scheduled tasks

We have a number of scheduled tasks on a server running under the same AD account. It turns out that the Temp folder in that account’s profile folder was blowing out to 100GB. We do specify the -noprofile option on each of the scheduled tasks. Is there any way of running powershell scheduled tasks without adding zillions of folders in the Temp folder?

The option -NoProfile of the PowerShell executable only means that no profile script will be loaded. The rest of the “mechanics” works just as usual and designed. So you will have to figure aout what script causes this behaviour to be able to prevbent it from happen. … or you add a “CleanUp” to one of your scripts to remove the temporary files left by any another script. :wink:

So, a question for Olaf. In Linux, you would define TEMP as /dev/null … and all output would go nowhere. Is there a way to do that in Powershell? set $ENV:Temp to /dev/null?

I don’t get how this is related to the initial question as you probably don’t want to eliminate the temporary folder at all - sometimes you need it.

But if you want to hide the output of some commands you can pipe it to Out-Null or you could use the dot net [Void] accelerator or you simply assign it to a variable.

I was just fishing for ideas since it seemed like the original post did not want anything going to %TEMP% / $ENV:Temp … Linux provides /dev/null that you can use for such things, just wondering if you as a PowerShell ZEN Master knew of some tricks in powershell to do the same.

I would expect that the files in the temp folder are needed at least once. So sending them to the nirvana righ away may break some functionalities. What’s bad on the other hand that the scripts do not seem to clean up after themselfs. :wink:

Nothing is actually being written to the Temp folder by the scripts. Somehow the script execution process has decided to write stuff there. There are folders that begin with ‘tmp_’ and they contain psd1, psm1 and ps1xml files.

Did you hire a magician to write those scripts for you? :wink: :wink:

Without any more detailed information we will not be able to help you with this issue. Scripts usually do not copy themselfs to toher folders.

I have to agree with Olaf. If you’re seeing those files in temp and your script does not write those files, then I would look elsewhere as the source. I’ve never seen any tmp_, ps1, ps1xml files created by powershell simply executing a script.

I think Ive found it:

			$global:EXSession = New-PSSession -Name ExchangeConn -ConfigurationName Microsoft.Exchange -ConnectionUri "http://$EXServer.$DomainDNS/PowerShell/" -Authentication Kerberos -ea Stop
			Import-Module (Import-PSSession $global:EXSession -allowclobber -DisableNameChecking -ea Stop) -Global -DisableNameChecking -Force -ea stop | out-null

Importing the exchange modules probably does it. Can’t find an option on import-module to specify destination though.

So you may add some code to remove the remote Exchange session you started. I’d expect that should clean up the temporary files used by the process. Otherwise you can add some cleanup code after you ran your Exchange related commands.

Yeh - Ive added cleanup code.