Share via


PowerShell COM Object in Scheduled Task

PowerShell COM Object in Scheduled Task

Issue

PowerShell Code Works Interactively but not in Scheduled Task.

Scenario

Using Office COM Object in Scheduled Job.

Code

$visio = New-Object -ComObject Visio.Application
$visio.Visible = $false

Error

  • Receive-Job : Exception calling "Open" with "1" argument(s): "
  • Receive-Job : You cannot call a method on a null-valued expression.
  • Receive-Job : You cannot call a method on a null-valued expression.

Solution

Reference Link

https://social.technet.microsoft.com/Forums/windowsserver/en-US/aede572b-4c1f-4729-bc9d-899fed5fad02/run-powershell-script-as-scheduled-task-that-uses-excel-com-object?forum=winserverpowershell

#32 Bit Operating System create a folder called c:\Windows\System32\config\systemprofile\Desktop
New-Item -Path c:\Windows\System32\config\systemprofile\Desktop -ItemType Directory -Force -Verbose
#64-bit Operating System create both c:\Windows\System32\config\systemprofile\Desktop and c:\Windows\SysWOW64\config\systemprofile\Desktop.
New-Item -Path C:\Windows\SysWOW64\config\systemprofile\Desktop -ItemType Directory -Force -Verbose

Good to use in Client SDK