I have a simple powershell script to enable a mailbox in Exchange called test.ps1. Here is the script:
add-pssnapin microsoft.exchange.management.powershell.admin Enable-Mailbox -Identity 'gi joe' -database 'myserver\myserver mailbox database 17'
If I go to the Powershell console and type
./test.ps1
It will run successfully. However, if I call it in VB.net using
Process.Start("powershell", "test.ps1")
the terminal flashes too quickly for me to see what it says, and it doesn't create the mailbox. Why does this happen, or how can I stop the terminal from disappearing before I can read the error?
To see what is going wrong try this instead:
Process.Start("powershell", "-noexit -file c:\<path>\test.ps1")
I suspect the error you get is because you aren't providing a full path to test.ps1.
Another possibility is that your 32-bit VB app needs to launch 64-bit Powershell (snapin or module may only be available there). In that case you need to invoke PowerShell by path and you have to use SysNative
in your path to be able to see the 64-bit PowerShell dir.
var powerShellPath = "C:\Windows\SysNative\WindowsPowerShell\v1.0\powershell.exe"
Process.Start(powerShellPath , "-noexit -file c:\<path>\test.ps1")
Sorry that's probably not proper VB syntax but should get you going.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With