I try to use this script to purge some log files of my exchange server.
I made just one small change and added the following line so that all Exchange objects are available.
add-pssnapin *exchange* -erroraction SilentlyContinue
When I run the script I get an error when the following lines are executed:
# Get a list of all Exchange 2013 servers
$Ex2013 = Get-ExchangeServer | Where {$_.IsE15OrLater -eq $true} | Sort-Object Name
$logger.WriteEventLog("Script started. Script will purge log files on: $($Ex2013)")
# Lets count the steps for a nice progress bar
$i = 1
$max = $Ex2013.Count * 2 # two actions to execute per server
The last line fires an error. As that the Count property isn't available. I have only one server, and if I execute exact those lines in my Exchange Management Shell this code executes without error.
What is the cause for the different behaviour?
PS: I currently have a workaround just to count the objects. And this works always:
$max = 0
foreach ($E15Server In $Ex2013) {
$max++
}
$max *= 2