Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ ASP and VBScript _ Vbscript Run Powershell Command

Posted by: jokeme71 Apr 10 2019, 07:32 PM

I can get the VBScript to run and open the PowerShell but I cannot get the additional Get-Content piece to work. How do I qualify it to run after the PowerShell is open?


objShell.Run("PowerShell -NoExit -Command Import-Module ProgramX; Write-Host 'Loading required modules. . .' | Get-Content X:\Data\Data.txt | ForEach-Object{Add-XPara -identity ""server\$_"" -Verbose -Confirm:$False}")

Posted by: cheekybuddha Apr 10 2019, 08:00 PM

Can you run this from a cmd window?

If so, what's the exact command you would use there?

My guess is that the -Command switch needs to be quoted, and the double quotes within it will need to be escaped.

(Disclaimer: complete guess!!!)

Try:

CODE
objShell.Run("PowerShell -NoExit -Command ""Import-Module ProgramX; Write-Host 'Loading required modules. . .' | Get-Content X:\Data\Data.txt | ForEach-Object{Add-XPara -identity \""server\$_\"" -Verbose -Confirm:$False}""")


hth,

d

Posted by: jokeme71 Apr 10 2019, 08:08 PM

I way over thought this (as I usually do things) The following worked perfectly. All that was needed was a semi-colon to separate the commands.

CODE
objShell.Run("PowerShell -NoExit -Command Import-Module ProgramX; Write-Host 'Loading required modules. . .'; Get-Content X:\Data\Data.txt | ForEach-Object{Add-XPara -identity ""server\$_"" -Verbose -Confirm:$False}")


Thanks for your help cheeky!

Posted by: cheekybuddha Apr 11 2019, 02:32 AM

Excellent, glad you got it sorted! thumbup.gif

d