DCOM error when using Scheduled tasks

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Vandrey Trindade Vandrey Trindade 1 year, 6 months ago.

  • Author
  • #24829
    Profile photo of Vandrey Trindade
    Vandrey Trindade


    I'm not sure if someone here can help me with this...
    I've created a powershell script using VMware PowerCLI to create an Excel file with ESXi servers information.
    It runs perfeclty when I run the script, but when I try to schedule a task it gives me the error below:

    New-Object : Exception Retrieving the COM class factory for component with CLSID
    CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005

    Additional information:
    I used to have this scheduled task on another machine using Office 2010. The only thing I have to do there was to create the two "Desktop" folders under system32/config/systemprofile and syswow64/config/systemprofile.
    Now I have a machine with Office 2013 (Click-to-run).

    The funny things is that it worked yesterday when I installed Lync... After updating Lync to Skype for business it stopped.
    Tried adding Network Service to Microsoft Excel Application security tab under DCOM configuration.
    No joy... Any light? =D

  • #24836
    Profile photo of Rob Simmers
    Rob Simmers

    Let's concentrate on the code that is having issues. Can you provide the code that is creating the scheduled task? Also tell us if you only run the scheduled task code on the servers, can you reproduce the error?

  • #24838
    Profile photo of Don Jones
    Don Jones

    Scheduled Tasks default to running under System, and it's likely that the Office COM object doesn't like running that user context. It's probably looking for a user profile and SYSTEM doesn't have one. And the difference from your old machine is probably that Office 2010 created a default user profile when it installed or something.

    That's my best guess. You seem to have a lot happening on that machine. And frankly, the idea of having Office installed on a server gives me shivers.

    As a suggestion – please don't think I'm crazy – have you considered using an actual database to store this information, rather than a spreadsheet? SQL Server Express is free, is designed to run as a service component, and is actually a lot easier to mess with than Excel. If you want reports from it, SQL Server Reporting Services is included with the big distribution of Express, and can generate some pretty mighty reports. We have a free ebook that covers some of the basics (Resources menu here on the site).

    But this business of using Excel as a database and reporting tool is something we admins need to talk away from.

  • #24848
    Profile photo of Vandrey Trindade
    Vandrey Trindade

    Rob Simmers and Don Jones,

    First, thanks for your time once again!

    I'm not running this on a server =p. I'm trying to run it on my workstation with "Windows 7 Professional" and "Office 2013 Home and business (Click-to-run)".
    The idea of having an Excel file is not to use it as an important database. We only need some fast and updated information about our servers. That's why the scheduled task only runs once in the day. Nothing really big deal, but we need to fill this file automatically.
    About the profile, that's the reason I've created those desktop folders on Windows\System32\config\systemprofile and Windows\SysWOW64\config\systemprofile.
    Read about it on this link (last post):
    And yes, I've tested and it works on a "Windows 7 Professional" with "Office 2010 (not click-to-run version)". We only have to create those two folders and it works.

    Let me try to show you what I'm doing:

    [b]1. Have PowerShell 4.0 and VMware PowerCLI 6 installed
    2. Created the script below [portuguese-brazilian][/b]

    $pwd = Get-Content C:\VMware\powerclicred | ConvertTo-SecureString
    $cred = New-Object System.Management.Automation.PSCredential "user$", $pwd
    Connect-VIServer -Server server1, server2, server3, server4, server5 -Credential $cred

    function HostInfo {
    $TotalGB = $Null
    $Datastores = Get-VMHost $ESXiServer.Name | Get-Datastore | Where {($_.Name -notlike "VMD*") -and ($_.Name -notlike "BKP*")}
    foreach ($Datastore in $Datastores) {
    $TotalGB += $Datastore.CapacityGB
    ($WorkBook01.Sheets.Item($ESXiServer.Name)).Cells.Item(7,2) = $ESXiServer.NumCpu
    ($WorkBook01.Sheets.Item($ESXiServer.Name)).Cells.Item(7,3) = ($ESXiServer | select @{N="RAM";E={[math]::Round($_.MemoryTotalGB,0)}}).RAM
    ($WorkBook01.Sheets.Item($ESXiServer.Name)).Cells.Item(7,4) = [math]::Round($TotalGB,0)
    ($WorkBook01.Sheets.Item($ESXiServer.Name)).Cells.Item(7,6) = "VMware "+($ESXiServer).Version+" build "+($ESXiServer).Build
    ($WorkBook01.Sheets.Item($ESXiServer.Name)).Cells.Item(7,7) = if ($ESXiServer.PowerState -eq 1){"Ligada"}else{"Desligada"}

    function Recursos {
    $ServidoresAtivos = Get-VM -Server $ESXiServer.Name | Where {$_.PowerState -eq "PoweredOn"}
    $CPUUtilizados = $Null
    $RAMUtilizada = $Null
    $TotalHD = $Null
    foreach ($CPU in $ServidoresAtivos.NumCpu){
    $CPUUtilizados += $CPU
    foreach ($RAM in $ServidoresAtivos.MemoryGB){
    $RAMUtilizada += $RAM
    $ServidorRAM = ($ESXiServer | select @{N="RAM";E={[math]::Round($_.MemoryTotalGB,0)}}).RAM
    $TotalCPU = $ESXiServer.NumCpu – $CPUUtilizados
    $Datastores = Get-VMHost $ESXiServer.Name | Get-Datastore | Where {($_.Name -notlike "VMD*") -and ($_.Name -notlike "BKP*")}
    foreach ($Datastore in $Datastores) {
    $TotalFreeGB += $Datastore.FreeSpaceGB
    ($WorkBook01.Sheets.Item($ESXiServer.Name)).Cells.Item(8,2) = $TotalCPU
    ($WorkBook01.Sheets.Item($ESXiServer.Name)).Cells.Item(8,3) = [math]::Round(($ServidorRAM – $RAMUtilizada),0)
    ($WorkBook01.Sheets.Item($ESXiServer.Name)).Cells.Item(8,4) = [math]::Round($TotalFreeGB,0)

    function ServerInfo {
    foreach ($Servidor in $Servidores) {
    $TotalHD = $Null
    $HardDisks = (Get-HardDisk $Servidor).CapacityGB
    foreach ($HardDisk in $HardDisks) {
    $TotalHD += $HardDisk
    ($WorkBook01.Sheets.Item($ESXiServer)).Cells.Item($Linha,1) = $Servidor.Name
    ($WorkBook01.Sheets.Item($ESXiServer)).Cells.Item($Linha,2) = $Servidor.NumCpu
    ($WorkBook01.Sheets.Item($ESXiServer)).Cells.Item($Linha,3) = [math]::Round($Servidor.MemoryGB)
    ($WorkBook01.Sheets.Item($ESXiServer)).Cells.Item($Linha,4) = [math]::Round($TotalHD,0)
    ($WorkBook01.Sheets.Item($ESXiServer)).Cells.Item($Linha,5) = (Get-Datastore -VM $Servidor.name).name
    ($WorkBook01.Sheets.Item($ESXiServer)).Cells.Item($Linha,6) = $Servidor.Guest.OSFullName
    ($WorkBook01.Sheets.Item($ESXiServer)).Cells.Item($Linha,7) = if ($Servidor.PowerState -eq 1){"Ligada"}else{"Desligada"}
    ($WorkBook01.Sheets.Item($ESXiServer)).Cells.Item($Linha,8) = $Servidor.Version.ToString()
    ($WorkBook01.Sheets.Item($ESXiServer)).Cells.Item($Linha,9) = ($Servidor.Guest.ExtensionData).ToolsStatus.ToString()
    ($WorkBook01.Sheets.Item($ESXiServer)).Cells.Item($Linha,10) = if (Get-VM $Servidor | Get-Snapshot){"Sim"}else{"Não"}
    #($WorkBook01.Sheets.Item($ESXiServer)).Columns.Item("A:I").EntireColumn.AutoFit() | out-null
    ($WorkBook01.Sheets.Item($ESXiServer)).Columns.Item("A:I").HorizontalAlignment = -4108
    $Linha = $Linha + 1

    $ESXiServers = Get-VMHost | Sort Name

    $Excel01 = New-Object -ComObject Excel.Application
    $Excel01.Visible = $False
    $Workbook01 = $Excel01.Workbooks.Open("C:\VMware\Arquivos\ConfigVirtual.xlsx")

    for ($i = 1; $i -le ($ESXiServers.Count); $i++)
    $WorkSheet = $WorkBook01.Sheets.Item($i)
    While ($Worksheet.Cells.Item(9,1).Value() -NotLike $Null){

    foreach ($ESXiServer in $ESXiServers) {

    foreach ($ESXiServer in $ESXiServers.Name) {
    $Linha = 9
    $Servidores = (Get-VM -Server $ESXiServer | Where {$_.Name -notlike "Unknown*"})

    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel01) | Out-Null
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Workbook01) | Out-Null
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Worksheet) | Out-Null
    $Excel01 = $Null

    [b]3. This scheduled task[/b]
    Run everyday at 5:00 a.m. this command: C:\VMware\AgConfigVirtual.bat

    [b]4. bat content[/b]
    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vimaxx.psc1" -command "[b]ampersand[/b]{C:\VMware\AgConfigVirtual.ps1}" > C:\VMware\Arquivos\ErrCmd.txt
    PS: The PSconsole file is another one that the default because I had to remove the PSModules info from it to work.
    PS2: Wrote ampersand because the special character was being erased of the final text.

    [b]5. Content of ErrCmd.txt file[/b]

    Name Port User
    —- —- —-
    server1 443 DOMAIN\user$
    server2 443 DOMAIN\user$
    server3 443 DOMAIN\user$
    server4 443 DOMAIN\user$
    server5 443 DOMAIN\user$

    New-Object : Falha na recupera‡Æo de f brica de classes COM do componente com
    CLSID {00024500-0000-0000-C000-000000000046} devido ao seguinte erro: 80080005
    Falha na execu‡Æo do servidor (Exce‡Æo de HRESULT: 0x80080005
    No C:\VMware\AgConfigVirtual.ps1:67 caractere:12
    + $Excel01 = New-Object -ComObject Excel.Application
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (:) [New-Object], COMExcept
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Comman

    A propriedade 'Visible' nÆo foi encontrada neste objeto. Verifique se a
    propriedade existe e pode ser definida.
    No C:\VMware\AgConfigVirtual.ps1:68 caractere:1
    + $Excel01.Visible = $False
    + ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
    ... etc etc ...

    I'm thinking on something about the click-to-run version of Office 2013 than is different that MSI installed version... The tricky thing is why it worked yesterday..........
    Every research I make it shows DCOM security settings (already done) and ASPNET on IIS (which I don't have on my machine).
    Sorry about the english. Trying to learn (english and powershell) =p

  • #24849
    Profile photo of Don Jones
    Don Jones

    Well, all I guess I can do is share what I'd do.

    Excel not working. Excel not a database. Could install SQL Server Express and have this done in 10 minutes, or continue fighting with crappy Excel COM object from the early 2000s.

    So I'd just install SQL Express and use that. Or output an object that PowerShell could run through Export-CSV, which could be opened by Excel, if that's the end goal. But Excel is always weird, and that's why I almost never waste time trying to make it work.

  • #24850
    Profile photo of Vandrey Trindade
    Vandrey Trindade

    Don Jones,

    My problem now is that my vacations starts this week. And to change the whole script is not an option for me now.... =/
    But since it works running manually, I'll let someone with this task =D
    When I come back I'll try your option!
    Thanks again!

You must be logged in to reply to this topic.