UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Vbscript Run Powershell Command    
 
   
jokeme71
post Apr 10 2019, 07:32 PM
Post#1



Posts: 926
Joined: 7-June 02
From: Maryland


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}")
Go to the top of the page
 
cheekybuddha
post Apr 10 2019, 08:00 PM
Post#2


UtterAccess VIP
Posts: 11,424
Joined: 6-December 03
From: Telegraph Hill


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

--------------------


Regards,

David Marten
Go to the top of the page
 
jokeme71
post Apr 10 2019, 08:08 PM
Post#3



Posts: 926
Joined: 7-June 02
From: Maryland


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!
This post has been edited by jokeme71: Apr 10 2019, 08:23 PM
Go to the top of the page
 
cheekybuddha
post Apr 11 2019, 02:32 AM
Post#4


UtterAccess VIP
Posts: 11,424
Joined: 6-December 03
From: Telegraph Hill


Excellent, glad you got it sorted! thumbup.gif

d

--------------------


Regards,

David Marten
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    22nd July 2019 - 12:33 AM