none
Scheduled script account large profile RRS feed

  • Question

  • Greetings,

    We have a scheduled powershell script that runs under a service account. I noticed today that the profile size for that service account was 45GB! The script is launched using the -noprofile switch. What else would cause a service account running a scheduled script to have such a large profile?

    Thanks

    David


    Sunday, May 26, 2019 10:01 PM

Answers

  • Delete the folder contents with a taks.

    I would suggest finding out what in the code is creating temporary files "Import-Module" does not do this.  There is something else running that is creating temp files.  Perhaps you have many copies of the task running.  Even with the modules there is no accounting for 45Gb. 

    I also recommend against running with "noprofile".  "noprofile" just says don't load the profile.  It does not say don't use it for things like temporary files.

    The scheduler will load the profile then powershell will run with no new copy.  It will use the already loaded copy.


    \_(ツ)_/

    • Marked as answer by David Zemdegs Sunday, May 26, 2019 11:12 PM
    Sunday, May 26, 2019 10:25 PM

All replies

  • I discovered that the issue was C:\users\<account>\appdata\local\Temp

    A new folder was created very time I ran:

    $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

    So that Import-Module command is filling it up.

    Other than deleting the profile every day - is there another solution?

    Sunday, May 26, 2019 10:15 PM
  • Delete the folder contents with a taks.

    I would suggest finding out what in the code is creating temporary files "Import-Module" does not do this.  There is something else running that is creating temp files.  Perhaps you have many copies of the task running.  Even with the modules there is no accounting for 45Gb. 

    I also recommend against running with "noprofile".  "noprofile" just says don't load the profile.  It does not say don't use it for things like temporary files.

    The scheduler will load the profile then powershell will run with no new copy.  It will use the already loaded copy.


    \_(ツ)_/

    • Marked as answer by David Zemdegs Sunday, May 26, 2019 11:12 PM
    Sunday, May 26, 2019 10:25 PM
  • Every time the script runs it creates a new subfolder under 

    'C:\users\<account>\appdata\local\Temp'

    In that sub folder are three files - a ps1xml, psd1 and psm1 which is why I assume its the import module command that is creating this stuff. The psm1 file contains all the exchange based cmdlets. The three files are 5.68MB and given this script runs several times a day, over time it fills up this subfolder. This script has been running for a  long time. I just found out about it cause the C drive filled up this morning.

    So you should never use '-noprofile' in scheduled scripts?

    Why would others think differently? e.g. http://www.powertheshell.com/bp_noprofile/

    Sunday, May 26, 2019 11:21 PM
  • The better question is, "why would you use it?"  What is the purpose.

    Never use any command or swttch/parameter that you don't understand.  This is a first rule of becoming a technician.  Copying and guesswork is for non-technical people.


    \_(ツ)_/

    Monday, May 27, 2019 12:34 AM
  • The PowerShell -NoProfile option prevents PowerShell from running profile scripts when you start it -- it has nothing to do with the user profile under which you run the PowerShell executable.


    -- Bill Stewart [Bill_Stewart]

    Monday, May 27, 2019 3:38 AM
    Moderator