Exchange Powershell from a Vbscript

I'm trying to enable mailbox from a VbsScript running a powershell command to a exchange powershell script:

objShell.Run "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -PSConsoleFile ´C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1´ -command ´C:\Temp\usu\CreateMail.ps1 HMATEST Espanya excservidor´"

But I'm having this error:

Missing expression after unary operator '-'.
At line:1 char:2
+ - <<<< PSConsoleFile ´C:\Program Files\Microsoft\Exchange Server\bin\exshell.
psc1´ -command ´C:\Temp\usu\CreateMail.ps1 HMATEST Espanya excservidor´
    + CategoryInfo          : ParserError: (-:String) [], ParentContainsErrorR
   ecordException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator

I thought could be due a special character "-" before "PSConsoleFile" and i tried sending with a vcbsript ASCII function Crh(45), Chr(150) and Chr(151) but the error still the same.

Any Idea?
Toni IsystemsCTOAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sirbountyCommented:
I think it's the apostrophe - try this:

objShell.Run "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -PSConsoleFile " & chr(34) & "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" & chr(34) & " -command " & chr(34) & "C:\Temp\usu\CreateMail.ps1 HMATEST Espanya excservidor" & chr(34) 

Open in new window

Toni IsystemsCTOAuthor Commented:
Thanks Sirbounty, but same result:

Missing expression after unary operator '-'.
At line:1 char:2
+ - <<<< PSConsoleFile C:\Program Files\Microsoft\Exchange Server\bin\exshell.p
sc1 -command C:\Temp\usu\CreateMail.ps1 HMATEST Espanya excservidor
    + CategoryInfo          : ParserError: (-:String) [], ParentContainsErrorR
   ecordException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator
Bill PrewIT / Software Engineering ConsultantCommented:
Just passing by, but how about this?

objShell.Run "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -PSConsoleFile ""C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1"" -command ""C:\Temp\usu\CreateMail.ps1 HMATEST Espanya excservidor"""

Open in new window

~bp
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Toni IsystemsCTOAuthor Commented:
Hi Bill,

exacly the same

Thks
sirbountyCommented:
Hmm - can you run that from a cmd prompt?

powershell -noext -PSConsolefile "%programfiles%\microsoft\exchange server\bin\exshell.psc1" -command "c:\temp\usu\CreateMail.ps1 HMATEST Espanya excservidor"
sirbountyCommented:
Powershell.exe is undoubtedly in your path, so you should be able to just run that without the path.
Next thing I would try is using the 8.3 equivalents to eliminate those internal quote needs.  Though, your single quote look more like some other character...that might cause an issue as well:
Copied from above compared to apostrophe:   ´ vs '
I'm more inclined to think that it's that single quote, rather than the hyphen you mentioned...

objShell.Run "powershell.exe -noexit -PSConsoleFile C:\Progra~1\Microsoft\Exchan~1\bin\exshell.psc1 -command C:\Temp\usu\CreateMail.ps1 HMATEST Espanya excservidor"

Also - does createmail.ps1 accept those 3 parameters?
What if you hard code those within your script?
Toni IsystemsCTOAuthor Commented:
Solved,
was something in the parameters order that didn't like to powersehll. I've changed the -noexit parametre from the first one to the last and it works:

objShell.Run "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1"" -noexit -command ""C:\Temp\usu\CreateMail.ps1 HMATEST Espanya excservidor"""

I was putting this parametre on the script only to check the result, now I've removed it from the script and still working fine.

Thanks for your help

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Toni IsystemsCTOAuthor Commented:
Sirbounty put me on the right path to solve it
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.