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
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
# 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
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