Link to home
Start Free TrialLog in
Avatar of Justin Murphy
Justin MurphyFlag for United States of America

asked on

VBA to run PowerShell script permission denied

I am attempting to help automate some reports my company generates on a monthly basis.

I have created a powershell script to pull the information from Office 365 that I need. This script functions in PowerShell and PowerShell ISE and outputs the data as desired.
Some of the data returned needs to be formatted so I was hoping I could start this process within Excel.

The workflow I'm hoping to get to is:

Macro Enabled Excel Template is Opened
Button is pressed that uses VBA to run the existing Powershell Script
The VBA imports the resulting CSV
Then use VBA to handle the formatting.

Where I am struggling is in getting VBA to get anywhere near being able to run anything via PowerShell

Just a small test is resulting with permission denied:


Option Explicit

Sub runPowershellScript()

Dim WshShell As Object

Set WshShell = CreateObject("WScript.Shell")

WshShell.Run "Powershell.exe"



End Sub

Open in new window


I get permission denied on this alone, it doesn't matter if I've started Excel as Admin or not.
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Where I am struggling is in getting VBA to get anywhere near being able to run anything via PowerShell

do you have problem when let's say running other program via CreateObject method?

Dim WshShell As Object

Set WshShell = CreateObject("WScript.Shell")

WshShell.Run "Notepad.exe"

Open in new window


if you still facing the issue, then the permission issue is not residing in powershell launching, and it could be on createobject triggering.

First, do you have any right to run PowerShell from the command prompt ?
If you can't, VBA can't.

ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial