Add office_365/connect_exchange
This commit is contained in:
1 parent
0b93e5c63e
commit
b8468c5672
1 file changed
+28
@@ -0,0 +1,28 @@
|
||||
function Connect-EXO {
|
||||
try {
|
||||
Write-Host "Connecting to Exchange Online (ISE Compatibility Mode)..." -ForegroundColor Cyan
|
||||
|
||||
# Inject C# code to allocate a temporary console footprint for ISE
|
||||
$consoleCode = @'
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
public class ISEConsoleFix {
|
||||
[DllImport("kernel32.dll", SetLastError = true)] public static extern int AllocConsole();
|
||||
[DllImport("kernel32.dll", SetLastError = true)] public static extern int FreeConsole();
|
||||
}
|
||||
'@
|
||||
Add-Type -TypeDefinition $consoleCode -ErrorAction SilentlyContinue
|
||||
|
||||
# Allocate the handle, connect using your working syntax, then free it
|
||||
[ISEConsoleFix]::AllocConsole() | Out-Null
|
||||
Connect-ExchangeOnline -UserPrincipalName "[email protected]" -DisableWAM -ShowBanner:$false
|
||||
[ISEConsoleFix]::FreeConsole() | Out-Null
|
||||
|
||||
$global:Connected = $true
|
||||
Write-Log "Connected to Exchange Online"
|
||||
} catch {
|
||||
# Ensure the handle is cleaned up if the login fails or is cancelled
|
||||
try { [ISEConsoleFix]::FreeConsole() | Out-Null } catch {}
|
||||
Write-Log "Connection failed: $_"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user