2

I'm a VBScript and PowerShell newbie. I have a PowerShell script that runs correctly when I call it from the command line. However when I try and call it from VBScript, it runs but does nothing.

The command I use on the CLI that works is

powershell.exe -nop -exec bypass -noni -command "& { . C:\<censored path>\testscript1.ps1; Get-Test }"

This works. When I run the following vbscript code, I get no results

Set objShell = CreateObject("Wscript.shell")
objShell.run("powershell.exe -nop -exec bypass -noni -command &""& { . C:\<censored path>\testscript1.ps1; Get-Test }" &"")

What am I doing wrong?

PS: After trimming down my command to:

objShell.run("powershell.exe -nop -exec bypass -noni -command "& { . C:\<censored path>\testscript1.ps1; Get-Test }" ")

I get a Code 800A0408 - Invalid Character error for the opening brace bracket. I have tried escaping both brackets, but I still get the same error.

1 Answer 1

2

You can try something like that :

PSCommand = "powershell.exe -nop -exec bypass -noni -command" & DblQuote("& { . C:\<censored path>\testscript1.ps1; Get-Test }")&""
MsgBox PSCommand 
set objShell = CreateObject("wscript.shell")
objShell.Run PSCommand
'****************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'****************************************************************
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.