• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 486
  • Last Modified:

Open Powershell (EMS) command within VBA Excel

HiHo folks,

this question refers to following thread:

Open Powershell (EMS) command within VBA Excel

I've still the problem thta i'm getting error message below:

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

File C:\users\username\desktop\settmb.ps1 cannot be loaded because the executi
on of scripts is disabled on this system. Please see "get-help about_signing" f
or more details.
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordE
    + FullyQualifiedErrorId : RuntimeException

Open in new window

If i start a EMS or Windows Powershell or VBS from Desktop directly it's running
without any problem.

I'm already set "unrestricted" to the 1st line of the script but same error.
The script should be executed from a command button in excel 2010.

Here's the code:
Private Sub CommandButton1_Click()
File = "c:\users\username\desktop\settmb.ps1"
  Set cell = ActiveSheet.Range("A12")

  ' Static content
  Set oFile = CreateObject("Scripting.FileSystemObject").CreateTextFile(File)
  oFile.WriteLine "Set-ExecutionPolicy unrestricted"
  oFile.WriteLine ". 'C:\exchsrvr\bin\RemoteExchange.ps1'"
  oFile.WriteLine "Connect-ExchangeServer -auto"

  While cell.Value <> ""
    oFile.WriteLine cell.Value
    Set cell = cell.Offset(1)
  Shell "powershell -noexit -file " & File
End Sub

and here the generated *ps1

Set-ExecutionPolicy unrestricted
. 'C:\exchsrvr\bin\RemoteExchange.ps1'
Connect-ExchangeServer -auto

Open in new window

appreciate for your help
  • 2
2 Solutions
You need to set the ExecutionPolicy to Unrestricted before you run the script.
Mandy_Author Commented:
Sorry that would be easy but not working
Mandy_Author Commented:
not solved
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now