Commit 29f780eb authored by Jos Lieben's avatar Jos Lieben

significantly speed up the exchange resilient connection function

parent 2555c18c
......@@ -11,23 +11,9 @@
$temporaryModulePath = (Join-Path $Env:TEMP -ChildPath "temporaryEXOModule")
$res = Export-PSSession -Session $Session -CommandName * -OutputModule $temporaryModulePath -AllowClobber -Force
$temporaryModulePath = Join-Path $temporaryModulePath -ChildPath "temporaryEXOModule.psm1"
Write-Verbose "Rewriting Exchange Online module, please wait a few minutes..."
$reader = [System.IO.File]::OpenText($temporaryModulePath)
[String]$newContent
$found = $False
while($null -ne ($line = $reader.ReadLine())) {
if(!$found -and $line.IndexOf("host.UI.PromptForCredential(") -ge 0){
$line = "-Credential `$global:o365Creds ``"
$found = $True
}
if($line){
$newContent += $line
}
$newContent += "`r`n"
}
$reader.Close()
$newContent | Out-File -FilePath $temporaryModulePath -Force -Confirm:$False -ErrorAction Stop
Write-Verbose "Rewriting Exchange Online module, please wait..."
$regex=’^.*\bhost\.UI\.PromptForCredential\b.*$’
(Get-Content $temporaryModulePath) -replace $regex, "-Credential `$global:o365Creds ``" | Set-Content $temporaryModulePath
$Session | Remove-PSSession -Confirm:$False
Write-Verbose "Module rewritten, re-importing..."
if($commandPrefix){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment