Link to home
Start Free TrialLog in
Avatar of jahhan
jahhan

asked on

Script Created in PowerGui taking a long time to load

I have several Powershell scripts, configured to retrieve information about MS Exchange 2003 services, taking a long time to display information through PowerGUI.  All of my scripts retrieve information for 25 servers.  Is there a reason as to why it take a long time to run some script and not others?
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image


Too many variables, it depends entirely on what each script does.

Chris
Avatar of jahhan
jahhan

ASKER

OK,
well this is one of the scripts that is slow to load.
------------------------------------------------------------------
$snServername='server01', 'server02' (all the way up to server25)
ForEach ($Srv in $snServerName)
{
$wmiServer = Get-Wmiobject -class Exchange_Server -computer $snServerName -namespace root\MicrosoftExchangeV2 #-ErrorAction SilentlyContinue
$cdoexmIExchangeServer = New-Object -com CDOEXM.ExchangeServer
$cdoexmIStorageGroup = New-Object -com CDOEXM.StorageGroup
$cdoexmIMailboxStoreDB = New-Object -com CDOEXM.MailboxStoreDB
#$cdoexmIExchangeServer.Datasource.Open(('LDAP://' + $wmiServer.DN))
$cdoexmIExchangeServer.Datasource.Open($Srv)
foreach ($sgStoragegroup in $cdoexmIExchangeServer.StorageGroups)
{
 if ($sgStoragegroup.Indexof("CN=Recovery Storage Group") -eq 0){"Recovery Storage Group"}
 else{
  $cdoexmIStorageGroup.DataSource.Open(('LDAP://' + $sgStoragegroup))
  foreach ($MailStore in $cdoexmIStorageGroup.MailboxStoreDBs)
  {
   $cdoexmIMailboxStoreDB.DataSource.Open(('LDAP://' + $MailStore))
   if($cdoexmIMailboxStoreDB.Status -eq 0){$cdoexmIMailboxStoreDB.Name + " Mounted"}
   if($cdoexmIMailboxStoreDB.Status -eq 1){$cdoexmIMailboxStoreDB.Name + " DisMounted"}
}
}
}
}
----------------------------------------------------------------------------------
I have to wait 10 minutes before the script completes.

Ouch, that's a long time.

You'd have to break it down further to figure out where it's slowing down. You could always insert a few Write-Host statements to mark progress.

Chris
Avatar of jahhan

ASKER

How do I go about creating write-host statements?
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jahhan

ASKER

thanks for this modified script.  I executed the script and it is stuck on "WMI Query".  In my testing environment it went through really quick (test environment only have one server).  In the production environment it did not even hit the first server yet and it has been 1 minute.

It could be trapped waiting for a timeout within WMI. It can be horribly slow if it does get stuck there. The namespace you're asking for isn't big, so I'd be surprised if it were more than that.

Have you tried executing just that command against the server in question separately?

Chris
Avatar of jahhan

ASKER

I have not ran the command against the server in question; however, I am about to do that now, and get back to you with my findings.
Avatar of jahhan

ASKER

Ok I was able to identify the server with the problem.  It seem as if my bridgehead server was the culprit.  After excluding the server from the script, it completed execution.
Avatar of jahhan

ASKER

The script is still not instant; however, it completes in a reasonable amount of time.