In a previous post (Warning when using exchange snap-in in PowerShell) I was asking how to properly connect to Exchange 2010 via powershell in a script with no output to the user because I am outputting Write-Host commands to the user and I don't want the warnings or output text from the Import-PSSession to interfere with my text being output to the user. We have since figured it out, but I am curious as to why my examples below do or do not work.
This DOES WORK:
$WarningPreference = "SilentlyContinue" $session = New-PSSession ` -ConfigurationName Microsoft.Exchange ` -ConnectionUri http://server.domain.com/PowerShell/ ` -Authentication Kerberos Import-PSSession $session | Out-Null
Does NOT WORK:
$session = New-PSSession ` -ConfigurationName Microsoft.Exchange ` -ConnectionUri http://server.domain.com/PowerShell/ ` -Authentication Kerberos Import-PSSession $session -WarningAction SilentlyContinue | Out-Null
Also does NOT WORK:
$session = New-PSSession ` -ConfigurationName Microsoft.Exchange ` -ConnectionUri http://server.domain.com/PowerShell/ ` -Authentication Kerberos Import-PSSession $session -WarningAction "SilentlyContinue" | Out-Null
Can anyone explain why changing the $WarningPreference to "SilentlyContinue" DOES work, but running "Import-PSSession $session -WarningAction SilentlyContinue" does NOT? Is my command not typed properly?
Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.