T
Tim Munro
Hi all,
I am running Windows XP SP3 with the Exchange 2007 (x86) Exchange
Management Tools installed.
I have VB.NET (2008) project underway that invokes a Powershell
subprocess using standard procedures found on the web. Generally it works
very well. I have successfully invoked the following PS commands and
returned their results:
Enable-Mailbox
New-Mailbox
Get-User
Get-MailUser
Get-Mailbox
But when I try Get-MailboxStatistics I get:
MapiExceptionLowLevelInitializationFailure: Unable to load exrpc32.dll or
one of its dependent DLLs (extrace.dll, exchmem.dll, msvcr80.dll, etc.)
All commands work perfectly in the Exchange Management Shell.
I've read the thread on the Web between "Mathias", "Karl Mitschke" and
"SvenC" but it just ends with no resolution.
Here's the Function:
Function RunExchCommand(ByVal PSCommand As Command) As IEnumerable
Dim RunSpace As Runspace
Dim RsConfig As RunspaceConfiguration
Dim SnapInInfo As PSSnapInInfo
Dim warning As PSSnapInException = New PSSnapInException()
Dim Results As IEnumerable
RsConfig = RunspaceConfiguration.Create
SnapInInfo =
RsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin",
warning)
If Not IsNothing(warning) Then
MsgBox("Error loading Exchange 2007 Management shell" & vbCrLf &
vbCrLf & warning.Message)
RunExchCommand = Nothing
Exit Function
End If
RunSpace = RunspaceFactory.CreateRunspace(RsConfig)
RunSpace.Open()
Dim MyPipeLine As Pipeline = RunSpace.CreatePipeline()
MyPipeLine.Commands.Add(PSCommand)
Try
Results = MyPipeLine.Invoke()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
Results = Nothing
End Try
RunExchCommand = Results
End Function
Here's the calling code snippet:
MyCommand = New Command("Get-MailboxStatistics")
MyCommand.Parameters.Add("Identity", sDN)
'
' It dies at this next command
'
' There's nothing here that I have not done elsewhere except the actual
PS command itself
'
PSResults = DirectCast(RunExchCommand(MyCommand), IList)
MBXStats = DirectCast(PSResults(0), PSObject)
If DirectCast(Mailbox.Properties("HiddenFromAddressListsEnabled").Value,
Boolean) Then
Hidden_chk.Checked = True
End If
If DirectCast(Mailbox.Properties("UseDatabaseQuotaDefaults").Value,
Boolean) Then
MBXDefaults_chk.Checked = True
Else
Warning_tbox.Text =
Mailbox.Properties("IssueWarningQuota").Value.ToString
NoSend_tbox.Text =
Mailbox.Properties("ProhibitSendQuota").Value.ToString
NoSendRec_tbox.Text =
Mailbox.Properties("ProhibitSendReceiveQuota").Value.ToString
End If
Needless to say any help would be greatly appreciated.
I am running Windows XP SP3 with the Exchange 2007 (x86) Exchange
Management Tools installed.
I have VB.NET (2008) project underway that invokes a Powershell
subprocess using standard procedures found on the web. Generally it works
very well. I have successfully invoked the following PS commands and
returned their results:
Enable-Mailbox
New-Mailbox
Get-User
Get-MailUser
Get-Mailbox
But when I try Get-MailboxStatistics I get:
MapiExceptionLowLevelInitializationFailure: Unable to load exrpc32.dll or
one of its dependent DLLs (extrace.dll, exchmem.dll, msvcr80.dll, etc.)
All commands work perfectly in the Exchange Management Shell.
I've read the thread on the Web between "Mathias", "Karl Mitschke" and
"SvenC" but it just ends with no resolution.
Here's the Function:
Function RunExchCommand(ByVal PSCommand As Command) As IEnumerable
Dim RunSpace As Runspace
Dim RsConfig As RunspaceConfiguration
Dim SnapInInfo As PSSnapInInfo
Dim warning As PSSnapInException = New PSSnapInException()
Dim Results As IEnumerable
RsConfig = RunspaceConfiguration.Create
SnapInInfo =
RsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin",
warning)
If Not IsNothing(warning) Then
MsgBox("Error loading Exchange 2007 Management shell" & vbCrLf &
vbCrLf & warning.Message)
RunExchCommand = Nothing
Exit Function
End If
RunSpace = RunspaceFactory.CreateRunspace(RsConfig)
RunSpace.Open()
Dim MyPipeLine As Pipeline = RunSpace.CreatePipeline()
MyPipeLine.Commands.Add(PSCommand)
Try
Results = MyPipeLine.Invoke()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
Results = Nothing
End Try
RunExchCommand = Results
End Function
Here's the calling code snippet:
MyCommand = New Command("Get-MailboxStatistics")
MyCommand.Parameters.Add("Identity", sDN)
'
' It dies at this next command
'
' There's nothing here that I have not done elsewhere except the actual
PS command itself
'
PSResults = DirectCast(RunExchCommand(MyCommand), IList)
MBXStats = DirectCast(PSResults(0), PSObject)
If DirectCast(Mailbox.Properties("HiddenFromAddressListsEnabled").Value,
Boolean) Then
Hidden_chk.Checked = True
End If
If DirectCast(Mailbox.Properties("UseDatabaseQuotaDefaults").Value,
Boolean) Then
MBXDefaults_chk.Checked = True
Else
Warning_tbox.Text =
Mailbox.Properties("IssueWarningQuota").Value.ToString
NoSend_tbox.Text =
Mailbox.Properties("ProhibitSendQuota").Value.ToString
NoSendRec_tbox.Text =
Mailbox.Properties("ProhibitSendReceiveQuota").Value.ToString
End If
Needless to say any help would be greatly appreciated.