Powershell to .exe - ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2'

Matt Wood 0 Reputation points
2024-08-03T05:54:42.7933333+00:00

I am having an issue converting a powershell script to .exe

The issue seems to lie with connecting to exchange. Is there a better way to do this when converting to .exe? When running in powershell it seems to work fine. Powershell version 7.4.4 ExchangeOnlineManagement 3.5.1

error

# Set the execution policy to Bypass for the current process
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force

# Function to install required modules if not already installed
function Install-ModuleIfRequired {
    param (
        [string]$ModuleName
    )
    
    # Check if module is already installed
    if (-not (Get-Module -Name $ModuleName -ListAvailable)) {
        Write-Host "Module '$ModuleName' is not installed. Installing..."
        Install-Module -Name $ModuleName -Force -Scope CurrentUser -AllowClobber -Repository PSGallery
    } else {
        Write-Host "Module '$ModuleName' is already installed."
    }
}

# List of required modules
$requiredModules = @("ExchangeOnlineManagement", "ActiveDirectory", "Microsoft.Graph")

# Install required modules if not already installed
foreach ($module in $requiredModules) {
    Install-ModuleIfRequired -ModuleName $module -Scope "CurrentUser"
}

# Load the required modules
Import-Module ExchangeOnlineManagement
Import-Module ActiveDirectory

# Prompt for admin ID and construct UPN
$adminID = Read-Host -Prompt "Enter your admin ID (without @dmyomain.com)"

# Connect to Exchange Online using device code authentication
Connect-ExchangeOnline -UserPrincipalName "$adminID@mydomain.com" -ShowBanner:$false
Connect-MgGraph -UseDeviceAuthentication -NoWelcome


Microsoft Exchange Online
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,615 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 34,516 Reputation points
    2024-08-03T13:32:36.65+00:00

    That looks like a problem with whatever tool you are using to convert the script to an .exe.

    https://github.com/MScholtes/PS2EXE

    Ps2exe has this switch.

     STA or MTA = 'Single Thread Apartment' or 'Multi Thread Apartment' mode
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.