I'm currently trying to write a skript that'll automatically connect to one of our exchange servers to open a exchange management shell remotely. This is the script I have written so far:
$servers = "ex1.domain.local", "ex2.domain.local"
$server = $servers[(Get-Random -Maximum $servers.count)]
$credential = Get-Credential domain\administrator -Message "Enter your login credentials"
write-host "Connecting remote PowerShell to $($server)..."
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://$server/PowerShell/ -Credential $credential
New-PSSession -Session $session -DisableNameChecking -AllowClobber
The script seems to run just fine but unfortunately the powershell console window immediately closes after New-PSSession -Session $session -DisableNameChecking -AllowClobber.
Whenever I paste these command into a powershell script seperately it works just fine.
How can I alter this script to not automatically close the console window after importing a powershelkl session?