Run SCSM script with windows Task Scheduler?

I am trying to run a SCSM script via windows task scheduler.  The script runs fine in the SCSM shell but not so much in powershell even after importing the module...so I think that I might be importing the incorrect module.  

If I open up a shell ps session and get-module it returns "System.Center.Service.Manager".  But that doesnt work when trying Import-Module.

So I have tried a few others such as:

import-module 'C:\Program Files\Microsoft System Center 2012\Service Manager\Powershell\System.Center.Service.Manager.psd1'
import-module 'C:\Program Files\Microsoft System Center 2012\Service Manager\Powershell\Microsoft.EnterpriseManagement.Core.Cmdlets\Microsoft.EnterpriseManagement.Core.Cmdlets.psd1'
import-module 'C:\Program Files\Microsoft System Center 2012\Service Manager\Powershell\Microsoft.EnterpriseManagement.ServiceManager.Cmdlets\Microsoft.EnterpriseManagement.ServiceManager.Cmdlets.psd1'
These don't work either.  Any help with importing SCSM PS modules are how to run SCSM script from task scheduler would be greatly appreciated!  Thanks.
July 12th, 2013 11:24am

Please post the error message for your standalone script.
Free Windows Admin Tool Kit Click here and download it now
July 14th, 2013 9:42pm

When I run the script in a non-SCSM PS Shell session I get this:

Get-SCSMObject : Cannot convert 'System.Object[]' to the type
'Microsoft.EnterpriseManagement.Configuration.ManagementPackClass' required by parameter 'Class'. Specified method is
not supported.
At C:\Scripts\UnassignedIncidentsMail-V0.4.ps1:34 char:38
+ $Incidents = @(Get-SCSMObject -Class $IncidentClass | where {($_.Status -eq $Act ...
+                                      ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-SCSMObject], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,SMLets.GetSMObjectCommand

I am trying to make a task for Andreas Unassigned incidents script.  The script works fine in the SCSM shell, but not in regular powershell even with Import-Module SMLets.

It seems that it still will not take the Get-SCSMObject command.

So I am wondering how to either launch a task with the SCSM PS shell, or how to import what is missing from the SMlets into the script.  

July 14th, 2013 11:42pm

I figured it out.  In a normal PS session I needed a $ after declaring the $IncidentClass variable.  

$IncidentClass = Get-SCSMClass -Name System.WorkItem.Incident$

This causes an error in the SCSM shell so i had removed it.  So now that I put it back the script runs fine in powershell but not the SCSM shell.  Which is fine because thats how I'll be using it.  

Free Windows Admin Tool Kit Click here and download it now
July 15th, 2013 8:57am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics