OpenAdapt icon indicating copy to clipboard operation
OpenAdapt copied to clipboard

[Bug]: The 'Set-ExecutionPolicy' command was found in the module 'Microsoft.PowerShell.Security', but the module could not be loaded.

Open abrichr opened this issue 1 year ago • 3 comments

Describe the bug

from @limaconnect on Discord:

Set-ExecutionPolicy : The 'Set-ExecutionPolicy' command was found in the module 'Microsoft.PowerShell.Security', but
the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Security'.
At line:341 char:1
+ Set-ExecutionPolicy RemoteSigned -Scope Process -Force
+ ~~~
    + CategoryInfo          : ObjectNotFound: (Set-ExecutionPolicy:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Note:

Please run Import-Module Microsoft.PowerShell.Security

Possibly related:

  • https://github.com/OpenAdaptAI/OpenAdapt/issues/581
  • https://github.com/OpenAdaptAI/OpenAdapt/issues/626

To Reproduce

On Windows 11 Pro:

  1. Download and install OpenAdapt from website
  2. Try running OpenAdapt via Installed Apps
  3. Observe Security Warning:

image

  1. ...?

abrichr avatar Oct 24 '24 16:10 abrichr

User subsequently attempted to install via install command on website:

Start-Process powershell -Verb RunAs -ArgumentList '-NoExit', '-ExecutionPolicy', 'Bypass', '-Command', "iwr -UseBasicParsing -Uri 'https://raw.githubusercontent.com/OpenAdaptAI/OpenAdapt/main/install/install_openadapt.ps1' | Invoke-Expression"

image

abrichr avatar Oct 24 '24 16:10 abrichr

Via ChatGPT (https://chatgpt.com/share/671a7949-2db8-8002-8d60-9bdf7ad52bbc):

The error indicates that PowerShell is unable to find or load the Microsoft.PowerShell.Security module, which contains the Set-ExecutionPolicy command. This might occur if the module is missing, corrupted, or not properly installed.

To address this, try the following steps:

  1. Ensure the module is available: Run the following command to check if Microsoft.PowerShell.Security is installed:

    Get-Module -ListAvailable Microsoft.PowerShell.Security
    
  2. Manually import the module: If the module is listed, manually import it:

    Import-Module Microsoft.PowerShell.Security
    
  3. Reinstall or repair PowerShell modules: If the module is missing or fails to import, reinstall or repair the PowerShell installation:

    • Open a PowerShell session as Administrator.
    • Reinstall the module:
      Install-Module -Name PowerShellGet -Force -AllowClobber
      Update-Module -Name Microsoft.PowerShell.Security
      
    • If issues persist, consider repairing PowerShell from Windows Features.
  4. Use an alternative to Set-ExecutionPolicy: If changing the execution policy is essential and the above steps fail, try setting it manually via the registry:

    • Open regedit and navigate to:
      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell
      
    • Adjust ExecutionPolicy to RemoteSigned.
  5. Administrator Permissions: Ensure that PowerShell is run as an Administrator, as changes to the execution policy might require elevated privileges.

If the problem persists, further investigation of the system's PowerShell environment might be needed.

abrichr avatar Oct 24 '24 20:10 abrichr

@0dm:

this could be because onedrive is being accessed instead of local documents

abrichr avatar Oct 24 '24 20:10 abrichr