Discussion:
Exchange Management Shell Command from vbscript
(too old to reply)
HPN/Holstebro-DK
2008-11-20 07:31:00 UTC
Permalink
hi,

How do I start an EMSC (Exchange Management Shell Command) from a vbscript?
I've tried something like this:

oShell.Run "PowerShell.exe -PSConsoleFile exshell.psc1 -noexit -command
Enable-DistributionGroup -identity " & GroupName, 1, True

It does start the Exchange Management Shell from PowerShell, but it does not
perform the command - in this case Mailenabling a distributiongroup.

Doing the same command from an Exchange Management Shell window is doing the
job OK.

So how do I do it from vbscript?

Any help is very appreciated.

Thanks,
Hans Peder
Shay Levy [MVP]
2008-11-20 09:34:04 UTC
Permalink
Hello HPN/Holstebro-DK,


Try with the full path to the exshell.psc1:

oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft\Exchange
Server\bin\exshell.psc1"" -noexit -command Enable-DistributionGroup -identity
" & GroupName ,1,True


---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar


H> hi,
H>
H> How do I start an EMSC (Exchange Management Shell Command) from a
H> vbscript? I've tried something like this:
H>
H> oShell.Run "PowerShell.exe -PSConsoleFile exshell.psc1 -noexit
H> -command Enable-DistributionGroup -identity " & GroupName, 1, True
H>
H> It does start the Exchange Management Shell from PowerShell, but it
H> does not perform the command - in this case Mailenabling a
H> distributiongroup.
H>
H> Doing the same command from an Exchange Management Shell window is
H> doing the job OK.
H>
H> So how do I do it from vbscript?
H>
H> Any help is very appreciated.
H>
H> Thanks,
H> Hans Pede
Joel (Jaykul) Bennett
2008-11-20 18:35:50 UTC
Permalink
Maybe you need to brace/quote it:

oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft
\Exchange Server\bin\exshell.psc1"" -noexit -command {Enable-
DistributionGroup -identity " & GroupName &"}",1,True

OR

oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft
\Exchange Server\bin\exshell.psc1"" -noexit -command ""Enable-
DistributionGroup -identity " & GroupName &"""",1,True

Either one should work (you can use single quotes, too). Also, if your
groupname can have spaces, you should quote that:

oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft
\Exchange Server\bin\exshell.psc1"" -noexit -command {Enable-
DistributionGroup -identity """ & GroupName &"""}",1,True
Post by Shay Levy [MVP]
Hello HPN/Holstebro-DK,
oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft\Exchange
Server\bin\exshell.psc1"" -noexit -command Enable-DistributionGroup -identity
" & GroupName ,1,True
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar
H> hi,
H>
H> How do I start an EMSC (Exchange Management Shell Command) from a
H>
H> oShell.Run "PowerShell.exe -PSConsoleFile exshell.psc1 -noexit
H> -command Enable-DistributionGroup -identity " & GroupName, 1, True
H>
H> It does start the Exchange Management Shell from PowerShell, but it
H> does not perform the command - in this case Mailenabling a
H> distributiongroup.
H>
H> Doing the same command from an Exchange Management Shell window is
H> doing the job OK.
H>
H> So how do I do it from vbscript?
H>
H> Any help is very appreciated.
H>
H> Thanks,
H> Hans Peder
HPN/Holstebro-DK
2008-11-21 08:15:01 UTC
Permalink
hi,

Neither of the proposals did the job:
First I tried this:
oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft
\Exchange Server\bin\exshell.psc1"" -noexit -command {Enable-
DistributionGroup -identity " & GroupName &"}",1,True

The command just showed up in the 'Exchange Management Shell'-window, but
did not execute the command-line: Enable-DistributionGroup -identity " &
GroupName


Then I tried the second proposal, but it did not even show the command-line.

Have you got any further ideas?

Hans Peder
Post by Shay Levy [MVP]
oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft
\Exchange Server\bin\exshell.psc1"" -noexit -command {Enable-
DistributionGroup -identity " & GroupName &"}",1,True
OR
oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft
\Exchange Server\bin\exshell.psc1"" -noexit -command ""Enable-
DistributionGroup -identity " & GroupName &"""",1,True
Either one should work (you can use single quotes, too). Also, if your
oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft
\Exchange Server\bin\exshell.psc1"" -noexit -command {Enable-
DistributionGroup -identity """ & GroupName &"""}",1,True
Post by Shay Levy [MVP]
Hello HPN/Holstebro-DK,
oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft\Exchange
Server\bin\exshell.psc1"" -noexit -command Enable-DistributionGroup -identity
" & GroupName ,1,True
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar
H> hi,
H>
H> How do I start an EMSC (Exchange Management Shell Command) from a
H>
H> oShell.Run "PowerShell.exe -PSConsoleFile exshell.psc1 -noexit
H> -command Enable-DistributionGroup -identity " & GroupName, 1, True
H>
H> It does start the Exchange Management Shell from PowerShell, but it
H> does not perform the command - in this case Mailenabling a
H> distributiongroup.
H>
H> Doing the same command from an Exchange Management Shell window is
H> doing the job OK.
H>
H> So how do I do it from vbscript?
H>
H> Any help is very appreciated.
H>
H> Thanks,
H> Hans Peder
Al Dunbar
2008-11-22 00:26:06 UTC
Permalink
Post by Shay Levy [MVP]
hi,
oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft
\Exchange Server\bin\exshell.psc1"" -noexit -command {Enable-
DistributionGroup -identity " & GroupName &"}",1,True
Is your powershell script in a file named "exshell.pcs1" or "exshell.ps1"?

/Al
Post by Shay Levy [MVP]
The command just showed up in the 'Exchange Management Shell'-window, but
did not execute the command-line: Enable-DistributionGroup -identity " &
GroupName
Then I tried the second proposal, but it did not even show the
command-line.
Have you got any further ideas?
Hans Peder
Post by Shay Levy [MVP]
oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft
\Exchange Server\bin\exshell.psc1"" -noexit -command {Enable-
DistributionGroup -identity " & GroupName &"}",1,True
OR
oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft
\Exchange Server\bin\exshell.psc1"" -noexit -command ""Enable-
DistributionGroup -identity " & GroupName &"""",1,True
Either one should work (you can use single quotes, too). Also, if your
oShell.Run "powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft
\Exchange Server\bin\exshell.psc1"" -noexit -command {Enable-
DistributionGroup -identity """ & GroupName &"""}",1,True
Post by Shay Levy [MVP]
Hello HPN/Holstebro-DK,
oShell.Run "powershell.exe -PSConsoleFile ""C:\Program
Files\Microsoft\Exchange
Server\bin\exshell.psc1"" -noexit -command
Enable-DistributionGroup -identity
" & GroupName ,1,True
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar
H> hi,
H>
H> How do I start an EMSC (Exchange Management Shell Command) from a
H>
H> oShell.Run "PowerShell.exe -PSConsoleFile exshell.psc1 -noexit
H> -command Enable-DistributionGroup -identity " & GroupName, 1, True
H>
H> It does start the Exchange Management Shell from PowerShell, but it
H> does not perform the command - in this case Mailenabling a
H> distributiongroup.
H>
H> Doing the same command from an Exchange Management Shell window is
H> doing the job OK.
H>
H> So how do I do it from vbscript?
H>
H> Any help is very appreciated.
H>
H> Thanks,
H> Hans Peder
Continue reading on narkive:
Loading...