AdhocAdam / smletsexchangeconnector

SMLets PowerShell based Exchange Connector for controlling Microsoft System Center Service Manager 2016+
https://adhocadam.github.io/smletsexchangeconnector/
GNU General Public License v3.0
29 stars 19 forks source link

Workflow Failed During Execution #421

Closed M4CR0S closed 2 years ago

M4CR0S commented 2 years ago

Describe the bug Execution error due run SMLets Connector. _Exception Message: The term 'Get-SCSMClass' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again._

Help us reproduce the bug Version of the connector you are using: SMLetsExchangeConnector 4.1.1.5 Features/variables you have enabled (i.e. $enableAzureCognitiveServicesForNewWI): No additional features are enabled

Expected behavior A clear and concise description of what you expected to happen.

Location and Environment Where are you running this from? Task Scheduler? SMA? Workflow server?: We execute it via imported Management Pack. What SCSM version are you running? 2022 10.22.1068.0

Additional context Here is exactly error message from event log:

A Windows Workflow Foundation workflow failed during execution.

Workflow Type: SMLets.Exchange.Connector.Resources.RunScript

Workflow Identifier: 7bdb4c11-31b8-bf66-e2ef-54de5d109462

Exception Type: System.Management.Automation.CommandNotFoundException

Exception Message: The term 'Get-SCSMClass' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Exception Stack: at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input) at SMLets.Exchange.Connector.Resources.RunScript.Execute(ActivityExecutionContext SMEXCOContext) at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime) at System.Workflow.Runtime.Scheduler.Run()

AdhocAdam commented 2 years ago

Judging by the error, it's as though SMLets isn't even installed despite that being part of the startup of the script. So I'm only guessing the workflow server is airgapped?

From an elevated PowerShell prompt on the workflow server run:

Install-Module SMLets

If the machine is airgapped, you'll need to install SMLets manually by downloading it from some internet connected machine here, copy it over, and install.

M4CR0S commented 2 years ago

Management Server is not airgapped. Trying execute "Get-SCSMClass" I get a list of possible Classes using my Admin Account, also using Workflow Account.

List

AdhocAdam commented 2 years ago

thinking

AdhocAdam commented 2 years ago
M4CR0S commented 2 years ago

SMLets Version: 4.1.1.5

IT's new installation from the scratch, no upgrades. SCSM 2022 and yes, I cannot get it running. Will try to execute PS-Script from console.

List

M4CR0S commented 2 years ago

I've try it execute manually from console, and it works. All test emails were pulled from inbox to scsm.

AdhocAdam commented 2 years ago

HRMMMMM

AdhocAdam commented 2 years ago

Well, I am definitely going to be thinking about this given what you've laid out here because something doesn't add up:

🤔

muradakram commented 2 years ago

Have you tried any of the solutions provided in this thread?

" https://social.technet.microsoft.com/Forums/en-US/7c00d9e1-40a6-4bc4-bd53-5326237f72a2/runbook-net-script-fails-with-error-quot-the-term-getscsmclass-is-not-recognized-as-the-name?forum=scogeneral "

On Wed, Nov 16, 2022 at 8:55 AM Adam @.***> wrote:

Well, I am definitely going to be thinking about this given what you've laid out here because something doesn't add up:

  • It will not run as the workflow account through SCSM workflows but it will run if you execute it manually in the console as the workflow account
  • The error cites it can't find the cmdlet (e.g. it believes SMLets isn't installed) and yet you can find the commands/SMLets no problem in the above screenshots + you're on the latest/stable release of SMLets (e.g. v1)

🤔

— Reply to this email directly, view it on GitHub https://github.com/AdhocAdam/smletsexchangeconnector/issues/421#issuecomment-1317150530, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEHC6WXG6HJ4OAQIIYUAQHLWITYWFANCNFSM6AAAAAASA5PAMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- MURAD AKRAM

*630-414-6731 - Cell708-316-8723 - Google @. @.>*

M4CR0S commented 2 years ago

@AdhocAdam strange thing, I see Workflow tries do query directory for file names "Get-SCSMClass" grafik

@muradakram thanks, unfortunately, here is not clear where I have to install "Orchestrator IP" and where is "PS Script Execution". SMLets seams to be already on the lates version. At the moment, I do not have orchestrator installed in my environment, yet.

AdhocAdam commented 2 years ago

But that is...interesting. I'll use the same approach and see what I can get.

M4CR0S commented 2 years ago

@AdhocAdam ;) thanks

AdhocAdam commented 2 years ago

Alright so I didn't see anything out of the ordinary in Procmon. In fact, my Procmon begins identically to what you have above. And after a significant amount of scrolling, I begin to see:

image

Which makes me think this is perhaps a red herring as eventually the process/script/workflow runs successfully for me and logs the event in the SMLets Exchange Connector log accordingly. But as I've thought about this, I need to correct a point I made earlier/above:

The first part isn't technically true because the workflow does run, the workflow does kick off the PowerShell, but it's within the PowerShell it fails and you get an event logged to the Operations Manager event log which would happen because I don't have error handling for this case as you've originally outlined. So all things considered, SCSM is doing everything it should be doing but the script portion is failing. I'm also assuming this is PowerShell 5.1 which would automatically know how to import any module as it's only looking in a handful of directories but for the sake of argument, can you open up smletsexchangeconnector.ps1 and place

Import-Module smlets -ErrorVariable moduleSMLets
"custom smexco event $($(Get-Date).ToLongTimeString())" | out-file c:\temp\result.txt
$moduleSMLets | Out-File c:\temp\result.txt -Append

on the very first three lines and see if you get the same result? Of course, check out the result.txt file created here for any errors importing the module.

M4CR0S commented 2 years ago

@AdhocAdam Yes, Yes, Yes Work as expected !!! One thing is, path, to customer event powershell script, should not have spaces otherwise it must be quoted.

AdhocAdam commented 2 years ago

Just to be clear, it now successfully imports the module, does not log any errors, and runs successfully?

Second, the path to the custom events script should be dot sourced in the Settings UI.

M4CR0S commented 2 years ago

@AdhocAdam Yes, No Errors more. E-Mails will be pulled from inbox successfully. Sure, path to custom ps is doted but either quoted or use path without spaces.

M4CR0S commented 2 years ago

@AdhocAdam Thanks For Your Quick Response And Support.

AdhocAdam commented 2 years ago

Thanks for using the connector. If you can spare a star for the repo it would be much appreciated 😄

M4CR0S commented 2 years ago

sure