none
Run Powershell script as Scheduled task, that uses Excel COM object

    Question

  • What am I missing here..

     

    I have  Powershell script that uses the Quest AD cmdlets to get computer information from AD and populate an Excel spreadsheet with the data.

    The script works fine, so I created a batch file and started the script from there (which works fine as well). It populates the excel spreadsheet, saves and closes the file.

    If I run the script as a scheduled task, I can see from the logging that it supposedly gets the computers from AD, and runs through them. But a file is never saved, I have tried to run the scheduled task with admin credentials.

    What am I forgetting?

    Thursday, November 11, 2010 12:21 PM

Answers

All replies

  • Is Excel installed for the admin account you are using?
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Thursday, November 11, 2010 1:17 PM
  • Yes.. I have tried running it under my own domain admin credentials that I have logged on to the server with, and I can start Excel just fine.

     

    Thursday, November 11, 2010 1:28 PM
  • Are there any diagnostic logging options for Excel you could turn on?


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Thursday, November 11, 2010 1:42 PM
  • Hi,

    I suggest we use Process Monitor to trace the process of the scheduled task:

    Process Monitor
    http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx   

    Download and run it. Click File menu, check Capture Events, try to run the task, when the error occurs, uncheck Capture Events again. Exported events to Logfile.PML and upload the file to Windows Live SkyDrive (http://www.skydrive.live.com/). If you would like other community member to analyze the report, you can paste the link here, if not, you can send the link to tfwst@microsoft.com (with this thread title or link in the email. Please don’t share documents with this address).

    Thanks.


    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Friday, November 12, 2010 11:47 AM
    Moderator
  • Can you post the script?

    Are you using relative paths?  You'll need to make sure you are using full paths, e.g., c:\output.xls - or make sure the starting directory is set.


    http://twitter.com/toenuff
    write-host ((0..56)|%{if (($_+1)%3 -eq 0){[char][int]("116111101110117102102064103109097105108046099111109"[($_-2)..$_] -join "")}}) -separator ""
    Friday, November 12, 2010 2:32 PM
  • I am using full paths, I have tried with both local paths and UNC paths.

    I will try to see what I can get out of Process monitor. My bet is that Excel is prompting for something, since I can see that it does not respond to the quit application either.. So when the scheduled task has run, it leaves an Excel process running.

    Friday, November 12, 2010 8:38 PM
  • Here is the script.

    $Descriptions = @{"ST" = "Scheduled Tasks";
    "LO" = "Logon After Reboot";
    "SS" = "Services";
    "CO" = "COM+ Objects";
    "AP" = "Applications Pools"}
    
    
    
    #$serverlist = Get-QADComputer -LdapFilter '(!(userAccountControl:1.2.840.113556.1.4.803:=2))' | where {$_.Osname -like "*server*"}
    $serverlist = Get-QADComputer -IncludedProperties pwdLastSet -SizeLimit 0  | where {$_.Osname -like "*server*"} | where {$_.name -like "apof*"}
    
    $erroractionpreference = "SilentlyContinue"
    $a = New-Object -comobject Excel.Application
    $a.visible = $false
    $a.DisplayAlerts = $false
    $a.AskToUpdateLinks = $false
    $a.AlertBeforeOverwriting = $false
    $a.FeatureInstall = "msoFeatureInstallNone"
    
    $b = $a.Workbooks.Add()
    $c = $b.Worksheets.Item(1)
    
    $c.Cells.Item(1,1) = "Machine Name"
    $c.Cells.Item(1,2) = "OS Name"
    $c.Cells.Item(1,3) = "IP Address"
    $c.Cells.Item(1,4) = "Ping Status"
    $c.Cells.Item(1,5) = "Password last set"
    $c.Cells.Item(1,6) = "Enabled/Disabled"
    $c.Cells.Item(1,7) = "Physical/Virtual"
    $c.Cells.Item(1,8) = "Description         "
    $c.Cells.Item(1,9) = "Test/Prod  "
    $c.Cells.Item(1,10) = "Patch  "
    $d = $c.UsedRange
    $d.Interior.ColorIndex = 19
    $d.Font.ColorIndex = 11
    $d.Font.Bold = $True
    
    $intRow = 2
    
    
    $colComputers = $serverlist
    foreach ($strComputer in $colComputers)
    {
    $c.Cells.Item($intRow, 1) = $strComputer.Name
    
    
    
    
    $ping = new-object System.Net.NetworkInformation.Ping
    $Reply = $ping.send($strComputer.Name)
    
    if ($Reply.status –eq “Success”) 
    #if (Test-Connection $strComputer.DnsName -Count 1 -Quiet ) 
    {
     $machineType = Get-WmiObject -ComputerName $strComputer.Name -Class Win32_BIOS
    
     If ($strComputer.AccountIsDisabled) {$enab = "Disabled"} else {$enab = "Enabled"}
     if ($strComputer.pwdLastSet -le (Get-Date).AddDays(-90)) {$age = "Older than 90 Days" ; $fgColor = 3} else {$age = "Less than 90 days"; $fgColor = 0}
    
     if ($machineType.Serialnumber -like "*vmware*") {$type = "VMware"} 
     Elseif ($machineType.Version -like "*VRTUAL*") {$type = "Hyper-V"} 
     Elseif (!($machineType.Version)) {$type = "N/A"} 
     else {$type = "Physical"}
     $Usetype = "Prod"
     $Patch = "Late Patch"
    
    [ARRAY]$DescriptionAR = ($strComputer).Description -split(",") | %{
    	Switch ($_) 
    		{
    			"T" {$Usetype = "Test"}
    			"S" {$Usetype = "Staging"}
    			"EP" {$Patch = "Early Patch"}
    			default {"$($Descriptions.get_item($_))"}
    
    		}
    
    }
    [String]$Description = $DescriptionAR -join("`r`n")
    
    $c.Cells.Item($intRow, 2) = $strComputer.OSName
    $c.Cells.Item($intRow, 3) = $Reply.Address.ToString()
    $c.Cells.Item($intRow, 4) = "Online"
    $c.Cells.item($intRow, 5).Interior.ColorIndex = $fgColor
    $c.Cells.Item($intRow, 5) = $age
    $c.Cells.Item($intRow, 6) = $enab
    $c.Cells.Item($intRow, 7) = $type
    $c.Cells.Item($intRow, 8) = $Description
    $c.Cells.Item($intRow, 9) = $Usetype
    $c.Cells.Item($intRow, 10) = $Patch
    
    $Reply = ""
    $Description = ""
    $intRow = $intRow + 1
    
    }
    else 
    {
     #$machineType = Get-WmiObject -ComputerName $strComputer.Name -Class Win32_BIOS
    $type = "N/A"
     If ($strComputer.AccountIsDisabled) {$enab = "Disabled"} else {$enab = "Enabled"}
     if ($strComputer.pwdLastSet -le (Get-Date).AddDays(-90)) {$age = "Older than 90 Days" ; $fgColor = 3} else {$age = "Less than 90 days"; $fgColor = 0}
    
     $Usetype = "Prod"
     $Patch = "Late Patch"
     
    [ARRAY]$DescriptionAR = ($strComputer).Description -split(",") | %{
    	Switch ($_) 
    		{
    			"T" {$Usetype = "Test"}
    			"S" {$Usetype = "Staging"}
    			"EP" {$Patch = "Early Patch"}
    			default {"$($Descriptions.get_item($_))"}
    
    		}
    
    }
    [String]$Description = $DescriptionAR -join("`r`n")
    
    
    
    $c.Cells.Item($intRow, 2) = $strComputer.OSName
    $c.Cells.Item($intRow, 3) = $Reply.Address.ToString()
    $c.Cells.Item($intRow, 4) = "Offline"
    $c.Cells.item($intRow, 5).Interior.ColorIndex = $fgColor
    $c.Cells.Item($intRow, 5) = $age
    $c.Cells.Item($intRow, 6) = $enab
    $c.Cells.Item($intRow, 7) = $type
    $c.Cells.Item($intRow, 8) = $Description
    $c.Cells.Item($intRow, 9) = $Usetype
    $c.Cells.Item($intRow, 10) = $Patch
    
    $Reply = ""
    $Description = ""
    $intRow = $intRow + 1  
    }
    $d.EntireColumn.AutoFit()
    $c.Rows.Autofit()
    
    }
    
    $b.SaveAs("C:\Tools\ComputerList\ServerList.xlsx")
    
    $a.Quit()
    
    

    Friday, November 12, 2010 9:00 PM
  • First off, to potentially eliminate this as either a Task Scheduler problem or credentials, can you try to write some of this off simply to a text file, without trying to invoke Excel?

    Not sure it will make any difference, but what OS and x86 or 64-bit?

    Sunday, November 14, 2010 3:41 PM
    Moderator
  • To solve the Excel not closing after the script finishes, add this to the begining of your script:

    function Release-Ref ($ref) {
    [System.Runtime.InteropServices.Marshal]::ReleaseComObject($ref)
    [System.GC]::Collect()
    [System.GC]::WaitForPendingFinalizers()
    }

    And this at the end:

    Release-Ref $d
    Release-Ref $c

    Release-Ref $b
    $a.Quit()
    Release-Ref $a

    You also might want to try making Excel visable and watching your script work with a subset of your servers, so that you can see what's happening.

     

    OldDog

    Sunday, November 14, 2010 5:22 PM
  • I have been playing with for some time.. and  it seems as if there are just things you cannot do with the Excel COM object, unless you are running in interactive mode.

    When using ProcessMon I can see that Excel does not query any paths or anything, even if I  add a default savepath, which it does when run interactively..

     

    Olddog I can output data to a text file no problem, so it has to do with Excel..

    So I guess I have to run the scheduled task as a logged in user.

    Tuesday, November 16, 2010 7:45 PM
  • Hi,

    Could the scheduled task run when configured to run as a logged in user? Do you need any other assistance? If there is anything we can do for you, please let us know.

    Thanks.


    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Friday, November 19, 2010 6:08 AM
    Moderator
  • I am just running this as a logged in user and it works... :)
    Sunday, December 05, 2010 8:27 PM

  • Glad to hear the task is working fine. If you have more questions in the future, you’re welcomed to this forum.

    Thanks.


    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Tuesday, December 07, 2010 2:32 AM
    Moderator
  • Hello, I believe the issue is with a bug in the excel object that does not aloow it to be run in a task in windows task scheduler unless the user has checked that the user has to be logged on to run. If you have it to run without user logged on the excel part of the script will not run correctly. I have been testing and breaking my head with this. here is my code
    $filenameB = "C:\Users\administrator\Documents\My Dropbox\2010-12-31_1510_SYSB_Last_Month_GroupName_Logins_GroupCalls.csv"
    $filenameC = "C:\Users\administrator\Documents\My Dropbox\2010-12-31_1510_SYSC_Last_Month_GroupName_Logins_GroupCalls.csv"
    $filenameE = "C:\Users\administrator\Documents\My Dropbox\2010-12-31_1510_SYSE_Last_Month_GroupName_Logins_GroupCalls.csv"
    
    
    
    $dataB = Import-Csv $filenameB
    $dataC = Import-Csv $filenameC
    $dataE = Import-Csv $filenameE
    #Creat a new excel Object
    $Excel = New-Object -ComObject Excel.Application
    #make it invisible
    $Excel.visible = $False
    #No alerts 
    $Excel.DisplayAlerts = $False
    #NOw we add a workbook
    $file1 = "C:\Users\administrator\Documents\My Dropbox\System_BCE_2011_TalkGroups_Logins_GroupCalls - Copy.xlsx"
    $Excel = $Excel.Workbooks.open($file1)
    $SheetB = $Excel.Worksheets.Item(1)
    $SheetC = $Excel.Worksheets.Item(2)
    $SheetE = $Excel.Worksheets.Item(3)
    $date = (Get-Date).AddMonths(-1)
    $month = Get-Date($date) -f "MM-yyyy"
    Switch ($month)
     {
      "12-2010" { $intRow = 5
              foreach ($line in $dataB)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetB.Cells.Item($intRow,2) = $line.UniqueID
                $SheetB.Cells.Item($intRow,5) = $line.logins
                $SheetB.Cells.Item($intRow,6) = $line.group_calls
    					  $intRow++
              }
    					$intRow = 5
    					foreach ($line in $dataC){
    						$SheetC.Cells.Item($intRow,2) = $line.UniqueID
                $SheetC.Cells.Item($intRow,5) = $line.logins
                $SheetC.Cells.Item($intRow,6) = $line.group_calls
    						$intRow++
    											}
    											$intRow = 5
    					foreach ($line in $dataE) {
    						$SheetE.Cells.Item($intRow,2) = $line.UniqueID
                $SheetE.Cells.Item($intRow,5) = $line.logins
                $SheetE.Cells.Item($intRow,6) = $line.group_calls
    						$intRow++
    											}
            }
            
           
     "01-2011" { $intRow = 5
              foreach ($line in $dataB)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetB.Cells.Item($intRow,2) = $line.UniqueID
                $SheetB.Cells.Item($intRow,7) = $line.logins
                $SheetB.Cells.Item($intRow,8) = $line.group_calls
    					$intRow++
    					}
    					$intRow = 5
    						foreach ($line in $dataC)
              {	$SheetC.Cells.Item($intRow,2) = $line.UniqueID
                $SheetC.Cells.Item($intRow,7) = $line.logins
                $SheetC.Cells.Item($intRow,8) = $line.group_calls
    						$intRow++
    					}
    					$intRow = 5
    						foreach ($line in $dataE)
    					{
    						$SheetE.Cells.Item($intRow,2) = $line.UniqueID
                $SheetE.Cells.Item($intRow,7) = $line.logins
                $SheetE.Cells.Item($intRow,8) = $line.group_calls
                $intRow++
              } 
            }
      "02-2011" { $intRow = 5
              foreach ($line in $dataB)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetB.Cells.Item($intRow,2) = $line.UniqueID
                $SheetB.Cells.Item($intRow,9) = $line.logins
                $SheetB.Cells.Item($intRow,10) = $line.group_calls
    						$intRow++
              }
    					$intRow = 5
    					foreach ($line in $dataC)
              {
    					$SheetC.Cells.Item($intRow,2) = $line.UniqueID
                $SheetC.Cells.Item($intRow,9) = $line.logins
                $SheetC.Cells.Item($intRow,10) = $line.group_calls
    						$intRow++
    					}
    					$intRow = 5
    					foreach ($line in $dataE)
              {
    					$SheetE.Cells.Item($intRow,2) = $line.UniqueID
                $SheetE.Cells.Item($intRow,9) = $line.logins
                $SheetE.Cells.Item($intRow,10) = $line.group_calls
    						$intRow++
    					}
            }
      "03-2011" { $intRow = 5
              foreach ($line in $dataB)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetB.Cells.Item($intRow,2) = $line.UniqueID
                $SheetB.Cells.Item($intRow,11) = $line.logins
                $SheetB.Cells.Item($intRow,12) = $line.group_calls
    						$intRow++
              } 
    					$intRow = 5
    					foreach ($line in $dataC)
              {
    						$SheetC.Cells.Item($intRow,2) = $line.UniqueID
                $SheetC.Cells.Item($intRow,11) = $line.logins
                $SheetC.Cells.Item($intRow,12) = $line.group_calls
    						$intRow++
              } 
    					$intRow = 5
    					foreach ($line in $dataE)
              {
    						$SheetE.Cells.Item($intRow,2) = $line.UniqueID
                $SheetE.Cells.Item($intRow,11) = $line.logins
                $SheetE.Cells.Item($intRow,12) = $line.group_calls
    						$intRow++
              } 
            }
      "04-2011" { $intRow = 5
              foreach ($line in $dataB)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetB.Cells.Item($intRow,2) = $line.UniqueID
                $SheetB.Cells.Item($intRow,13) = $line.logins
                $SheetB.Cells.Item($intRow,14) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
    					foreach ($line in $dataC)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetC.Cells.Item($intRow,2) = $line.UniqueID
                $SheetC.Cells.Item($intRow,13) = $line.logins
                $SheetC.Cells.Item($intRow,14) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
    					foreach ($line in $dataE)
              {
                
                $SheetE.Cells.Item($intRow,2) = $line.UniqueID
                $SheetE.Cells.Item($intRow,13) = $line.logins
                $SheetE.Cells.Item($intRow,14) = $line.group_calls
                $intRow++
              } 
            }
      "05-2011" { $intRow = 5
              foreach ($line in $dataB)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetB.Cells.Item($intRow,2) = $line.UniqueID
                $SheetB.Cells.Item($intRow,15) = $line.logins
                $SheetB.Cells.Item($intRow,16) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
    					 foreach ($line in $dataC)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetC.Cells.Item($intRow,2) = $line.UniqueID
                $SheetC.Cells.Item($intRow,15) = $line.logins
                $SheetC.Cells.Item($intRow,16) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
    					 foreach ($line in $dataE)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetE.Cells.Item($intRow,2) = $line.UniqueID
                $SheetE.Cells.Item($intRow,15) = $line.logins
                $SheetE.Cells.Item($intRow,16) = $line.group_calls
                $intRow++
              } 
            }
      "06-2011" { $intRow = 5
              foreach ($line in $dataB)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetB.Cells.Item($intRow,2) = $line.UniqueID
                $SheetB.Cells.Item($intRow,17) = $line.logins
                $SheetB.Cells.Item($intRow,18) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
              foreach ($line in $dataC)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetC.Cells.Item($intRow,2) = $line.UniqueID
                $SheetC.Cells.Item($intRow,17) = $line.logins
                $SheetC.Cells.Item($intRow,18) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
              foreach ($line in $dataE)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetE.Cells.Item($intRow,2) = $line.UniqueID
                $SheetE.Cells.Item($intRow,17) = $line.logins
                $SheetE.Cells.Item($intRow,18) = $line.group_calls
                $intRow++
              } 
            }
      "07-2011" { $intRow = 5
              foreach ($line in $dataB)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetB.Cells.Item($intRow,2) = $line.UniqueID
                $SheetB.Cells.Item($intRow,19) = $line.logins
                $SheetB.Cells.Item($intRow,20) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
              foreach ($line in $dataC)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetC.Cells.Item($intRow,2) = $line.UniqueID
                $SheetC.Cells.Item($intRow,19) = $line.logins
                $SheetC.Cells.Item($intRow,20) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
              foreach ($line in $dataE)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetE.Cells.Item($intRow,2) = $line.UniqueID
                $SheetE.Cells.Item($intRow,19) = $line.logins
                $SheetE.Cells.Item($intRow,20) = $line.group_calls
                $intRow++
              } 
            }
      "08-2011" { $intRow = 5
              foreach ($line in $dataB)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetB.Cells.Item($intRow,2) = $line.UniqueID
                $SheetB.Cells.Item($intRow,21) = $line.logins
                $SheetB.Cells.Item($intRow,22) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
              foreach ($line in $dataC)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetC.Cells.Item($intRow,2) = $line.UniqueID
                $SheetC.Cells.Item($intRow,21) = $line.logins
                $SheetC.Cells.Item($intRow,22) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
              foreach ($line in $dataE)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetE.Cells.Item($intRow,2) = $line.UniqueID
                $SheetE.Cells.Item($intRow,21) = $line.logins
                $SheetE.Cells.Item($intRow,22) = $line.group_calls
                $intRow++
              } 
            }
      "09-2011" { $intRow = 5
              foreach ($line in $dataB)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetB.Cells.Item($intRow,2) = $line.UniqueID
                $SheetB.Cells.Item($intRow,23) = $line.logins
                $SheetB.Cells.Item($intRow,24) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
              foreach ($line in $dataC)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetC.Cells.Item($intRow,2) = $line.UniqueID
                $SheetC.Cells.Item($intRow,23) = $line.logins
                $SheetC.Cells.Item($intRow,24) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
              foreach ($line in $dataE)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetE.Cells.Item($intRow,2) = $line.UniqueID
                $SheetE.Cells.Item($intRow,23) = $line.logins
                $SheetE.Cells.Item($intRow,24) = $line.group_calls
                $intRow++
              } 
            }
      "10-2011" { $intRow = 5
              foreach ($line in $dataB)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetB.Cells.Item($intRow,2) = $line.UniqueID
                $SheetB.Cells.Item($intRow,25) = $line.logins
                $SheetB.Cells.Item($intRow,26) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
              foreach ($line in $dataC)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetC.Cells.Item($intRow,2) = $line.UniqueID
                $SheetC.Cells.Item($intRow,25) = $line.logins
                $SheetC.Cells.Item($intRow,26) = $line.group_calls
                $intRow++
              }
    					$intRow = 5
              foreach ($line in $dataE)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetE.Cells.Item($intRow,2) = $line.UniqueID
                $SheetE.Cells.Item($intRow,25) = $line.logins
                $SheetE.Cells.Item($intRow,26) = $line.group_calls
                $intRow++
              } 
            }
      "11-2010" { $intRow = 5
              foreach ($line in $dataB)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetB.Cells.Item($intRow,2) = $line.UniqueID
                $SheetB.Cells.Item($intRow,27) = $line.logins
                $SheetB.Cells.Item($intRow,28) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
              foreach ($line in $dataC)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetC.Cells.Item($intRow,2) = $line.UniqueID
                $SheetC.Cells.Item($intRow,27) = $line.logins
                $SheetC.Cells.Item($intRow,28) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
              foreach ($line in $dataE)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetE.Cells.Item($intRow,2) = $line.UniqueID
                $SheetE.Cells.Item($intRow,27) = $line.logins
                $SheetE.Cells.Item($intRow,28) = $line.group_calls
                $intRow++
              } 
            }
      "12-2011" { $intRow = 5
              foreach ($line in $dataB)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetB.Cells.Item($intRow,2) = $line.UniqueID
                $SheetB.Cells.Item($intRow,29) = $line.logins
                $SheetB.Cells.Item($intRow,30) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
              foreach ($line in $dataC)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetC.Cells.Item($intRow,2) = $line.UniqueID
                $SheetC.Cells.Item($intRow,29) = $line.logins
                $SheetC.Cells.Item($intRow,30) = $line.group_calls
                $intRow++
              } 
    					$intRow = 5
              foreach ($line in $dataE)
              {
                #put the data into these cells and repeat down
                #write-host $line.UniqueID $line.GroupName $line.agency $line.Division $line.logins $line.group_calls
                $SheetE.Cells.Item($intRow,2) = $line.UniqueID
                $SheetE.Cells.Item($intRow,29) = $line.logins
                $SheetE.Cells.Item($intRow,30) = $line.group_calls
                $intRow++
              } 
            }
     }
    $SheetB.SaveAs($file1)
    $Excel.Close()
    
    #Email Section Part 1
    #Setting Up My PSCRedentials
    $secpasswd = ConvertTo-SecureString "password$" -AsPlainText -Force
    $mycreds = New-Object System.Management.Automation.PSCredential("tech", $secpasswd)
    #Send email using send-mailmessage
    send-mailmessage -to scotta@me.tv-from "Automated Monthly Report<ScottA@me.com>" -subject "Previous Month's Logins&GroupCalls For Systems(B,C,E)" -body "Please let me know if you have any questions. "
     -attachments $file1 -smtpserver techjunkie.tv -Cc scotta@email.org-credential $mycreds
    
     
    

    Let me know what you think.

    Visit my site for other scripts for your use.

    PowerShell Tips, SQL Examples, Learn Php

    Scott your Tech From Miami

    Sunday, January 02, 2011 1:09 AM
  • Just to second that- in very similar scenario, powershell running from task scheduler, writing to excel, will not Save the excel workbook unless "user has to be logged on to run" is checked.  If the user is logged on, and the PC is locked, it will indeed run and save the file... This happens to work for my situtation.

    Monday, October 03, 2011 3:14 PM
  • I too have run into this problem and did not find a solution. Only way was as said

    "user has to be logged on to run"

    Maybe a fix for the future?

    Saturday, January 07, 2012 10:40 PM
  • Hi,

    there is a solution in another thread which I can't find yet. So sorry for not linking to it.

     

    You have to create a folder (or two on a 64bit-windows):

    (32Bit, always)

    C:\Windows\System32\config\systemprofile\Dektop

    (64Bit)

    C:\Windows\SysWOW64\config\systemprofile\Desktop

     

    I have had the same problem and this was the only solution i have found.

    • Proposed as answer by cml9076 Monday, April 02, 2012 8:55 PM
    Sunday, January 08, 2012 12:01 PM
  • Thank you for that JensKalski.....that seems to do the trick.
    Sunday, January 08, 2012 8:24 PM
  • JensKalski

    Well I'll be damned, that did the trick!  Great find!

    Monday, April 02, 2012 8:56 PM
  • Hi,

    there is a solution in another thread which I can't find yet. So sorry for not linking to it.

    You have to create a folder (or two on a 64bit-windows):

    (32Bit, always)

    C:\Windows\System32\config\systemprofile\Dektop

    (64Bit)

    C:\Windows\SysWOW64\config\systemprofile\Desktop

    I have had the same problem and this was the only solution i have found.

    Thanks Jens!

    http://www.patton-tech.com/2012/05/printing-from-scheduled-task-as.html


    Jeffrey S. Patton Assistant Director of IT School of Engineering Computing Services University of Kansas 1520 West 15th Street Lawrence, KS. 66045-7621 | http://patton-tech.com

    Saturday, May 19, 2012 9:10 PM
  • Works a treat, thanks Jens.
    Thursday, June 21, 2012 2:27 PM
  • This worked for me too - thanks!
    Monday, August 06, 2012 2:00 PM
  • Hi,

    there is a solution in another thread which I can't find yet. So sorry for not linking to it.

     

    You have to create a folder (or two on a 64bit-windows):

    (32Bit, always)

    C:\Windows\System32\config\systemprofile\Dektop

    (64Bit)

    C:\Windows\SysWOW64\config\systemprofile\Desktop

     

    I have had the same problem and this was the only solution i have found.

    Wow it worked for me! (note the first folder name is Desktop not dektop). I was having a problem with the excel saveas command in a powershell script when it was being called from within a SQL command on a sql server.  Which is basically the same as the way the scheduled task runs them.  Definitely a Bug somewhere, likely in the Excel Com Objects.

    Tags: ComObject Excel.Application .SaveAs Powershell TransactSQL Stored procedure


    Windows Server Administrator

    Tuesday, August 21, 2012 8:05 PM
  • I tried just adding the Desktop folder and it did not solve my problem.  Turns out it was due to permissions for the service account I was using to run the scheduled task.  

    If you are running the task as a user without local admin privileges there are a few other settings which need to be changed beyond adding the Desktop folder.

    For the account you have specified for running the task:  (Paths below are in system32 or SysWow64 depending on 64 or 32bit.)

      • Add Local Launch and Local Activation permissions to the Microsoft Excel Application DCOM Config.
      • Grant "Read & Execute, List folder contents, Read" permissions on the \config\systemprofile\Desktop folder.
      • Grant "Modify, Read & Execute, List Folder Content, Read, Write" permissions for the account on the following folders:
        \config\systemprofile\AppData\Roaming\Microsoft
        \config\systemprofile\AppData\Local\Microsoft

    Check out the link below for full directions.

    http://troyvssharepoint.blogspot.com/2012/07/stumbled-upon-interesting-one-today.html

    Tuesday, September 11, 2012 3:10 PM
  • I'm also looking for a solution to generating a excel file within a powershell script run as scheduled task.

    I've tried to create the folders as listet, but this does not do the trick for me.

    I'm running on Windows Server 2012, maybe this is the problem? The scheduled task is configured to "Run with highest privileges" and "Configure for: Windows Server 2012". But also when "Configure for: Windows Server 2008 R2" is set, it does not help.

    My user used for the scheduled task has Admin-Rights on the server and when logging in with it the script works fine. When running as scheduled task the script only sends an email, without generating the excel file (and sending it as attachment).

    Thursday, February 07, 2013 6:50 AM
  • Mansch, you have me worried.  I had this problem, and created the folders, and it now works as a Scheduled Task on Server 2008 R2 - but I am going to be trying to migrate to Server 2012.

    Let me know if you get anywhere with this.

    I might try the permissions that Onpeak above talked about on my Server 2012 machine.

    jj


    jj John Thayer Jensen, System Administrator, Digital Services, The University of Auckland Business School Room 260-4136, 12 Grafton Road DDI: +64 9 923-7543 Mobile (work): +64 21 83-3586 Mobile (personal): +64 21 85-1904 quickdial: 60001 FAX: +64 9 373-7696 http://inquietumcor.blogspot.com

    Tuesday, May 07, 2013 2:45 AM
  • Hmmm, would be interesting to know if the same config that worked for you with 2008 R2 will also work with 2012.

    Maybe you could keep us informed, as I have not found any other special solution for 2012 yet.

    Tuesday, May 07, 2013 7:53 AM
  • This was a good find!  I was about to re-write my entire script because I couldn’t export the data to excel.

    Thank you VERY much for posting!

    Mark

    Saturday, July 20, 2013 12:46 PM
  • I have the same problem with Excel on a Windows Server 2012, which is invoked by a C# program via Microsoft.Office.Interop.Excel. It runs when started by doubleclicking at the program. When i start it via scheduler it generates an exception at:

    wk=excel.Workbooks.Add(Type.Missing);

    The error message:

    Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space.

     • To make more memory available, close workbooks or programs you no longer need.

     • To free disk space, delete files you no longer need from the disk you are saving to.

    __________________________________________________________________________________

    i start the program with scheduler and the same user, which is able to start it by doubleclicking.

    i have set the checkbox "With highest privileges". The free memory is about 1 GB.

    I tried to add the "Desktop"-folder as described above and which works for Windows Server 2008.

    Nothing helped. I am at a loss. Has someone experience with such problems on Windows Server 2012?


    elu

    Monday, July 29, 2013 11:28 AM
  • Seems you have got the same problem as I have and that this solution does not work with Windows Server 2012.

    Is there any other option to make an excel file without using Excel? ;)

    Monday, July 29, 2013 11:35 AM
  • not really, because this program is taking the data from SAP and generates a list of open sales orders grouped by week of delivery.

    This file is for end-users and they don't want to open an ascii-file with excel and grouping the data by themself.


    elu

    Monday, July 29, 2013 11:47 AM
  • Not really any other option or not really the same problem?

    I also try to make an excel file (with PowerShell).

    And I know other programs, that create excel files, that do not use excel APIs, but instead generate an excel file (xls format).

    Monday, July 29, 2013 11:54 AM
  • I don't know if this will help anyone running Server 2012 but I had a like problem on Windows Server 2008 R2 using PowerShell 3 and Excel 2003 SP3 as a COM object.  My script and task would work fine unless running the task with "Run whether user is logged on or not" was checked.  In that case no Excel file would be created and I would get Windows Logs, System events like the following:

    The machine-default permission settings do not grant Local Activation permission for the COM Server application with CLSID {00024500-0000-0000-C000-000000000046} and APPID Unavailable
     to the user DOMAIN\thicks SID (S-1-5-21-1437597970-832611207-2781745148-1166) from address LocalHost (Using LRPC). This security permission can be modified using the Component Services administrative tool.

    The solution was to run DCOMCNFG and right click on Component Services, Computer, My Computer and choose Properties.  Then on the COM Security tab, Launch and Activation Permissions, Edit Default I added the specific user that was running the script, checked all four boxes and life is good again!

    Tuesday, July 30, 2013 3:06 PM
  • Seems not to work with Windows Server 2012.
    Wednesday, July 31, 2013 2:43 PM
  • Very helpful thread - thanks to all who have posted. I can confirm that Onpeak's steps worked on Win7-64, using PowerShell 64-bit with COM activation of 32-bit Excel 2010. Both the DCOM tweak and the .\Desktop folder creation were required.
    Wednesday, September 04, 2013 7:09 PM
  • I have create PowerShell Excel Export that works without COM and without Excel!
    look if this solves your Problems on Server 2012:

    http://gallery.technet.microsoft.com/scriptcenter/Export-XLSX-PowerShell-f2f0c035


    Please click “Mark as Answer” if my post answers your question and click “Vote As Helpful” if my Post helps you.
    Bitte markiere hilfreiche Beiträge von mir als “Als Hilfreich bewerten” und Beiträge die deine Frage ganz oder teilweise beantwortet haben als “Als Antwort markieren”.
    My PowerShell Blog http://www.admin-source.info
    [string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('755964655967-86965747271757624-8796158066061').substring(($_*2),2))})-replace' '
    German ? Come to German PowerShell Forum!


    • Edited by Peter Kriegel Saturday, September 07, 2013 3:37 PM fggfg
    Saturday, September 07, 2013 3:36 PM
  • Can this Excel Export Script also work with formatting and multiple sheets?
    Monday, September 09, 2013 7:22 AM
  • Can this Excel Export Script also work with formatting and multiple sheets?

    No!

    But in a first step you can Export PowerShell Objects to an Excel workbook worksheet.

    And in a second step you can do formatting (with COM). 


    Please click “Mark as Answer” if my post answers your question and click “Vote As Helpful” if my Post helps you.
    Bitte markiere hilfreiche Beiträge von mir als “Als Hilfreich bewerten” und Beiträge die deine Frage ganz oder teilweise beantwortet haben als “Als Antwort markieren”.
    My PowerShell Blog http://www.admin-source.info
    [string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('755964655967-86965747271757624-8796158066061').substring(($_*2),2))})-replace' '
    German ? Come to German PowerShell Forum!

    Monday, September 09, 2013 12:03 PM
  • I can confirm it runs OK in a 2012 server environment.  We have a powershell script that is using the Excel COM object.
    Friday, February 14, 2014 8:59 PM
  • This worked great.

    Any explanation as to why this works?  Why would Excel start under the system profile instead of the profile the script is running under?

    Thanks! 

    Friday, February 21, 2014 5:40 PM
  • This solved a long pending problem of mine. Thank you soooo much.:)

    Sunday, March 02, 2014 1:36 AM
  • Holy Guacamole! Not sure if I should jump up with joy or punch someone. This solution works and also makes no sense. In case someone got as confused as I did, you just have to create the folder below and do nothing else ...and my Excel files get generated by my task scheduler application!

    =======================

    Hi,

    there is a solution in another thread which I can't find yet. So sorry for not linking to it.

    You have to create a folder (or two on a 64bit-windows):

    (32Bit, always)

    C:\Windows\System32\config\systemprofile\Desktop

    (64Bit)

    C:\Windows\SysWOW64\config\systemprofile\Desktop

    I have had the same problem and this was the only solution i have found.

    Thursday, March 06, 2014 11:04 PM
  • Thanks Jens Kalski it did fixed the issue... 

    VVinayPrasad

    Tuesday, April 01, 2014 10:28 AM
  • I have not been able to get this to work on 2012. I've stooped to running it with my own account, which is an admin on the box. I've created the Desktop folders for the systemprofile, I've checked DCOM permissions and even though I'm an administrator, I specifically added my user account. I've tried running in 2008, 2008R2 and 2012 modes. I've run x86 PowerShell, x64 PowerShell, I've changed COM permissions, tried running it with -noexit... I've run procmon and I can see that Excel opens the CSV I'm converting, but it doesn't seem to do the SaveAs. I've checked file and share permissions.... I'm pretty much at a loss. It runs every time without fail from the console, it's just that I can't get it to run as a scheduled task.

    Any thoughts as to what else I could be missing? I'm beyond grasping at straws at this point.

    Edit: Figured it out. After some more time with Procmon, I found that Excel was trying to do a CreateFile operation in C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\Temporary Internet Files

    The problem was the Temporary Internet Files folder didn't exist in that location. Once I added that folder and re-ran my scheduled task, it worked just fine.


    • Edited by WBrady1965 Wednesday, April 30, 2014 7:22 PM Update
    • Proposed as answer by Iroqouiz Friday, October 17, 2014 7:47 AM
    Wednesday, April 30, 2014 6:32 PM
  • That solved my problem.

    Monday, May 12, 2014 11:01 AM
  • Holy Guacamole! Not sure if I should jump up with joy or punch someone. This solution works and also makes no sense. In case someone got as confused as I did, you just have to create the folder below and do nothing else ...and my Excel files get generated by my task scheduler application!

    =======================

    Hi,

    there is a solution in another thread which I can't find yet. So sorry for not linking to it.

    You have to create a folder (or two on a 64bit-windows):

    (32Bit, always)

    C:\Windows\System32\config\systemprofile\Desktop

    (64Bit)

    C:\Windows\SysWOW64\config\systemprofile\Desktop

    I have had the same problem and this was the only solution i have found.

    When I tried this, my reaction was similar. 

    But the most important thing is: After many spent hours trying different proposed solutions,  FINALLY, IT WORKS.

    Happy user

    Monday, May 12, 2014 11:05 AM
  • I have not been able to get this to work on 2012. I've stooped to running it with my own account, which is an admin on the box. I've created the Desktop folders for the systemprofile, I've checked DCOM permissions and even though I'm an administrator, I specifically added my user account. I've tried running in 2008, 2008R2 and 2012 modes. I've run x86 PowerShell, x64 PowerShell, I've changed COM permissions, tried running it with -noexit... I've run procmon and I can see that Excel opens the CSV I'm converting, but it doesn't seem to do the SaveAs. I've checked file and share permissions.... I'm pretty much at a loss. It runs every time without fail from the console, it's just that I can't get it to run as a scheduled task.

    Any thoughts as to what else I could be missing? I'm beyond grasping at straws at this point.

    Edit: Figured it out. After some more time with Procmon, I found that Excel was trying to do a CreateFile operation in C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\Temporary Internet Files

    The problem was the Temporary Internet Files folder didn't exist in that location. Once I added that folder and re-ran my scheduled task, it worked just fine.


    Thank you! This solved my problem on Server 2012, tried everything else in this thread.
    Friday, October 17, 2014 7:48 AM
  • Hi WBrady1965 and Iroqouiz,

    I have the similar issue, the schedule task run the task and when it took the out to a file, i get the following error.

    Exception calling "Add" with "0" argument(s): "Microsoft Excel cannot open or 
    save any more documents because there is not enough available memory or disk 
    space. 
     To make more memory available, close workbooks or programs you no longer 
    need. 
     To free disk space, delete files you no longer need from the disk you are 
    saving to."
    At D:\Scripts\test.ps1:24 char:1
    + $workbook = $excel.Workbooks.Add()
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : ComMethodTargetInvocation
     
    (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull
     
    You cannot call a method on a null-valued expression.
    At  D:\Scripts\test.ps1:26 char:1
    + $failedclient.Cells.Item(1,1) = 'SL No'

    Thursday, November 13, 2014 3:22 PM
  • Hi Vishsb,

    has the excel file macros in it? In my case it had to do with security problems. I added the path of the excel file in the trusted pathes and then it worked. You can also try to open the excel file on the machine where the script runs with the same user as the scrupt runs and then check if it the options button appears.

    regards

    elu


    elu

    Friday, November 14, 2014 6:36 AM
  • Wow,

    I used this solution on 2008 Server R2.

    It work like a charm. Thanks

    :-)

    Friday, January 02, 2015 7:14 PM
  • Nice! I've added at start of my PS script:

    # Excel cannot open file bug fix
    if (-Not (Test-Path C:\Windows\System32\config\systemprofile\Dektop)) { New-Item C:\Windows\System32\config\systemprofile\Dektop -type Directory }
    if (-Not (Test-Path C:\Windows\SysWOW64\config\systemprofile\Desktop)) { New-Item C:\Windows\SysWOW64\config\systemprofile\Desktop -type Directory }
    
    Works fine now.

    Windows Server 2012 R2

    Runs without stored password or highest privileges.

    Thursday, January 15, 2015 10:45 AM
  • Beware of your typo here:

    if (-Not (Test-Path C:\Windows\System32\config\systemprofile\Dektop)) {
        New-Item C:\Windows\System32\config\systemprofile\Dektop -type Directory
    }

    This error will only affect 64 bit processes.  The 32 bit version in SysWow64 is correct in the above examples.


    ¯\_(ツ)_/¯


    • Edited by jrvModerator Thursday, January 15, 2015 11:29 AM
    Thursday, January 15, 2015 11:28 AM
    Moderator
  • Hi,

    there is a solution in another thread which I can't find yet. So sorry for not linking to it.

     

    You have to create a folder (or two on a 64bit-windows):

    (32Bit, always)

    C:\Windows\System32\config\systemprofile\Dektop

    (64Bit)

    C:\Windows\SysWOW64\config\systemprofile\Desktop

     

    I have had the same problem and this was the only solution i have found.

    I, too, was experiencing the same issue on Windows Server 2012 R2 x64 and Excel 2013. Sadly, this did not work for me. I did get it working however and wanted to post for anyone else still struggling with this problem.

    First I was getting an access denied error. I created the above folders without it working. I then went into Component Services >  Microsoft Excel Application >  Launch and Activation Permissions and explicitly added my account (I was part of the admin group which was already there, but wanted to rule it out). That didn't work. I then explicitly added the account to My Computer > Com Permissions > Both Launch and Access permissions (Again, I was part of the admin group, but wanted to rule it out). Once adding my account there the access denied error message went away.

    Then I started getting the "Failed to open" error that I see a lot of people getting. I had already added the desktop folders to no avail. I added the following folders per the post above:

    C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\Temporary Internet Files
    
    C:\Windows\SysWOW64\config\systemprofile\AppData\Roaming\Microsoft\Windows\Temporary Internet Files
    
    C:\Windows\System32\config\systemprofile\AppData\Local\Microsoft\Windows\Temporary Internet Files
    
    C:\Windows\System32\config\systemprofile\AppData\Roaming\Microsoft\Windows\Temporary Internet Files

    Still didn't work. So I ran ProcMon and started looking at what was being referenced. I found two additional directories it was trying to reference and was failing:

    C:\Windows\SysWOW64\config\systemprofile\Documents
    
    C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\INetCache

    Once I added those two additional directories, my files opened properly using the Excel COM object without needing to be logged in.

    Sorry for the long post, but I wanted to include all troubleshooting attempts I made as I have not gone back and checked which ones were needed and which ones were not. But I wanted to get the fix out there to help others having the same frustrations I have had the past 2 days.



    • Edited by James Culpovich Tuesday, May 26, 2015 1:43 PM Corrected post referrence
    • Proposed as answer by teh dave Tuesday, October 20, 2015 2:43 AM
    Thursday, May 21, 2015 1:40 PM
  • Mind explaining how this affects the service account's security wrapper? I am not using the service account.

    Additionally, How is adding my name to a list that I am already a part of open me up to many attacks?
    Friday, May 22, 2015 2:48 PM
  • Mind explaining how this affects the service account's security wrapper? I am not using the service account.

    Additionally, How is adding my name to a list that I am already a part of open me up to many attacks?

    Sorry - I thought you had posted that you added you account to the folders security.  I see I misread the post.

    If you don't change security on system objects in the system folders then you are probably ok.  Expect that the script will continue to break for new reasons as MS tightens the security on the system. Be careful that you use full paths in your scripts that run under scheduler as the default will be the system profile. 

    Be sure to set "Start In" to an accessible location for the account running the script.

     


    \_(ツ)_/

    Friday, May 22, 2015 3:00 PM
    Moderator
  • Boy - that worked for me!!!!  I could generate Excel file on local drive but not on network drive.  Checked to make sure all 8 directories existed - if not I made them.  Running server 2012 - running scheduled task as server 2008.
    Tuesday, August 11, 2015 7:42 PM
  • Thank, it saved my day! 
    Wednesday, September 30, 2015 12:28 PM
  • Of everything on here, this post lead me in the right direction, thank you.
    Monday, November 23, 2015 8:05 PM
  • Many Thanks Jens!
    Wednesday, December 02, 2015 3:20 PM
  • Many many thanks to you...
    Friday, April 22, 2016 3:30 PM
  • Thanks for all the tips. Still not fixed by Microsoft - Windows 2012R2. Got it running with th ehelp of you guys!
    Thursday, September 22, 2016 2:31 AM
  • Hi,

    there is a solution in another thread which I can't find yet. So sorry for not linking to it.

     

    You have to create a folder (or two on a 64bit-windows):

    (32Bit, always)

    C:\Windows\System32\config\systemprofile\Dektop

    (64Bit)

    C:\Windows\SysWOW64\config\systemprofile\Desktop

     

    I have had the same problem and this was the only solution i have found.

    Thank you JensKalski, can't believe that worked!
    Saturday, October 15, 2016 4:01 PM
  • Thank you Jens Kalsk!!!!!!!!!!!!!!!!!!!!!!!!!!! Created an account just to come here and say that.
    • Edited by AndyJAllen Thursday, January 12, 2017 3:33 PM
    Thursday, January 12, 2017 2:52 PM
  • Thank you so much. I was able to resolve my issues on Server 2012 by adding the Desktop folders as indicated elsewhere as well as the INetCache folder which you mentioned. I did not end up needing the Temporary Internet Files folders, nor the Documents, but we may be performing some different Excel functions.

    º¿º

    Friday, February 03, 2017 9:32 PM
  • Microsoft support and tech keep warning people that Office products will not run correctly under the scheduler or a y other service.  They can destabilize and crash a system.

    \_(ツ)_/

    Friday, February 03, 2017 9:47 PM
    Moderator