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
   xception
    + 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)
  Wend
  oFile.Close
  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
LVL 2
Mandy_Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

munkyjimCommented:
You need to set the ExecutionPolicy to Unrestricted before you run the script.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mandy_Author Commented:
Sorry that would be easy but not working
0
Mandy_Author Commented:
not solved
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.