Run a Powershell command (not script) from Excel VBA Run a Powershell command (not script) from Excel VBA vba vba

Run a Powershell command (not script) from Excel VBA


To run an inline Powershell command, you'll probably need to use the -Command param and surround your statement with quotes. It'll also be easier if you use single quotes within the command.

Try this out:

pscmd = "PowerShell -Command ""{Get-ScheduledTask -TaskName 'My Task' -CimSession MYLAPTOP}"""


Haven't tested but this but the execution policy may be a factor.

pscmd = "PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command {" & _Chr(34) & "Get-ScheduledTask" & _  " -TaskName " & Chr(34) & "My Task" & Chr(34) & _  " -CimSession MYLAPTOP" & Chr(34) & "}"