Justin Murphy
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:
I get permission denied on this alone, it doesn't matter if I've started Excel as Admin or not.
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
I get permission denied on this alone, it doesn't matter if I've started Excel as Admin or not.
First, do you have any right to run PowerShell from the command prompt ?
If you can't, VBA can't.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
do you have problem when let's say running other program via CreateObject method?
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.