Dim results As ICollection(Of PSObject)
Dim rc As RunspaceConfiguration = RunspaceConfiguration.Create()
Dim snapEx As PSSnapInException = Nothing
Dim info As PSSnapInInfo = rc.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", snapEx)
Dim myRunSpace As Runspace = RunspaceFactory.CreateRunspace(rc)
myRunSpace.Open()
Dim pipeLine As Pipeline = myRunSpace.CreatePipeline()
Using pipeLine
' Modified constructor for Command to include boolean flag
' indicating command is a script
Dim getSize As New Command("Get-MailboxStatistics -server exch.xyz.com | fl Identity, TotalItemSize", True)
pipeLine.Commands.Add(getSize)
results = pipeLine.Invoke()
If results IsNot Nothing AndAlso results.Count > 0 Then
For Each ps As PSObject In results
If ps.Members("TotalItemSize").Value IsNot Nothing Then
Dim tempsize As String
tempsize = ps.Members("TotalItemSize").Value
tempsize.Replace("B", "")
tempsize = tempsize / 1024
htExMBSizes.Add(ps.Members("Identity").Value, tempsize)
End If
Next
End If
End Using
|