0

The rundeck is unable to execute powershell script with import-module even I install the 'Microsoft.Online.SharePoint.PowerShell' module in the target server.

[ERROR ] Execution finished with the following error (winrm-exec.py:332)[root]

[ERROR ] Import-Module : The specified module 'Microsoft.Online.SharePoint.PowerShell' was not loaded because no valid module file was found in any module directory.

I try to remove 'Import-Module Microsoft.Online.SharePoint.PowerShell -Verbose' command but I'm getting this error.

[ERROR ] Execution finished with the following error (winrm-exec.py:332)[root]

[ERROR ] Connect-SPOService : The term 'Connect-SPOService' 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.

I already install ' Microsoft.Online.SharePoint.PowerShell' module in the target server but still getting an issue.

Microsoft.Online.SharePoint.PowerShell

Here's my code:

Set-ExecutionPolicy RemoteSigned -Scope Process -Force
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

#endregion
$username = "user_name"
$password = "password"
$siteUrl = "https://xxxx.sharepoint.com/"
# Connect to Azure AD
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username, $(convertto-securestring $password -asplaintext -force)
Connect-SPOService -Url $siteUrl -Credential $cred -ModernAuth $true -AuthenticationUrl https://login.microsoftonline.com/organizations -WarningAction SilentlyContinue
6
  • Hi, could you share the Rundeck job definition to take a look? also, can you double-check that you have that module installed following this? sharepointdiary.com/2016/11/… Commented Dec 5, 2024 at 11:46
  • Hi @MegaDrive68k, please check 'Microsoft.Online.SharePoint.PowerShell' link. I post the screenshot that the module is installed in the target server. Commented Dec 5, 2024 at 13:30
  • What about the job definition? docs.rundeck.com/docs/learning/tutorial/… Can you share it to take a look? Also, ensure you're not facing a double-hop scenario: stackoverflow.com/a/63618033/10426011. Additionally take a look at these answers: stackoverflow.com/questions/58640044/…. Regards! Commented Dec 5, 2024 at 13:48
  • I can't give you the details of the job definition since it was confidential. Can I know what specific you want to check in the job definition? Commented Dec 6, 2024 at 7:01
  • Is your job trying to do a double hop? like this: github.com/rundeck-plugins/py-winrm-plugin/issues/… Commented Dec 6, 2024 at 12:54

1 Answer 1

0

Can you verify that the account that runs the process on the server has access to the Microsoft.Online.SharePoint.PowerShell module? Login to the system as the user and run Get-Module Microsoft.Online.SharePoint.PowerShell -ListAvailable

If that doesn't return anything, add the module's installation folder to the user's PSModulePath environment variable.

Sign up to request clarification or add additional context in comments.

1 Comment

yes, and I got a return. ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Binary 16.0.25... Microsoft.Online.SharePoint.Powe... {New-SPOListFileVersionBatchDeleteJob, Remove-SPOListFileVersionBatchDeleteJob, Get-SPOListF... This means that the module is already installed in the server.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.