-
Notifications
You must be signed in to change notification settings - Fork 0
/
Powershell.vbs
40 lines (27 loc) · 963 Bytes
/
Powershell.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'Set objShell = CreateObject("Wscript.shell")
'objShell.run("powershell -noexit -file c:\fso\CleanupFiles.ps1")
'objShell.run("powershell -command {Write-Out 'Hello World!'}")
' CallPowerShell.vbs
' Call PowerShell from VBScript
' Author: ITomation (http://itomation.ca)
' Version 1.0 - 2015-11-27
' --------------------------------------------'
'On Error Resume Next
Option Explicit
Dim strPSCommand
Dim strDOSCommand
Dim objShell
Dim objExec
Dim strPSResults
' Construct PowerShell Command (PS syntax)
strPSCommand = "write-host 'Hello World!'"
' Consruct DOS command to pass PowerShell command (DOS syntax)
strDOSCommand = "cmd /c start /min powershell -windowstyle hidden -command " & strPSCommand & ""
' Create shell object
Set objShell = CreateObject("Wscript.Shell")
' Execute the combined command
Set objExec = objShell.Exec(strDOSCommand)
' Read output into VBS variable
strPSResults = objExec.StdOut.ReadAll
' Echo results
Echo strPSResults