Reputation: 1
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
Upvotes: 0
Views: 62
Reputation: 1
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.
Upvotes: 0