1

Hi can someone pls help me to run powershell from vbscript as a administrator

VB Script

MyPath = "c:\temp\folder1" Dim objShell Set objShell = CreateObject("Wscript.Shell") objShell.run("powershell.exe -noexit -file C:\temp\power.ps1 " & MyPath)

PowerShell power.ps1

C:\temp\psfile.exe $args[0] -c

4
  • Why are you trying to run a PowerShell script to run an external command instead of directly running the external command from VBScript? Commented Jun 21, 2016 at 9:43
  • Hi psfile command will make use of administrator user id and password and have to put in external file ... Commented Jun 21, 2016 at 10:12
  • I have to close all the connection in folder/sub-folders that are open in rempte share using psfile command. in psfile I have to use remote server administrator id and password to achieve this Commented Jun 21, 2016 at 10:14
  • Hi can someone pls help me to run powershell from vbscript as a administrator VB Script ----------- MyPath = "c:\temp\folder1" Dim objShell Set objShell = CreateObject("Wscript.Shell") objShell.run("powershell.exe -noexit -file C:\temp\power.ps1 " & MyPath) PowerShell power.ps1 --------------------- C:\temp\psfile.exe $args[0] -c Commented Jun 21, 2016 at 13:03

1 Answer 1

0

In VBScript Set is used for objects; so change

set input ="C:\temp\folder1\"

to

input = "C:\temp\folder1\"
Sign up to request clarification or add additional context in comments.

7 Comments

tried but no luck.. I have to close all remote connections that were in folder1 share and under it's sub folders
Also, $input is a PowerShell automatic variable that doesn't work as the OP seems to expect. What the OP actually wants to use there is $args[0].
File C:\temp\power.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details. At line:1 char:35 + C:\temp\power.ps1 <<<< c:\temp\folder1 + CategoryInfo : NotSpecified: (:) [], PSSecurityException + FullyQualifiedErrorId : RuntimeException
@user1954762 Which part of 'Please see "get-help about_signing" for more details' did you not understand? Please do some legwork yourself. We're not here to spoon-feed you a solution to your problem.
now it seems it's working fine when I send it as argument but same when I send via vbscript I am getting error as access denied.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.