locked
Executing a PS1 file from within a Powershell script RRS feed

  • Question

  • I am not sure if this is harder than it seems, or my brain has just had enough for the day.  I would like to start consolidating my scripts down so that I have a number of scripts that I can load from within another script to cut down on redundancy, and also just in case it needs to change, I can change it in one file instead of a whole bunch of scripts.  

    Whenever I try to execute a script from within another script  get the box that pops up and asks if i would like to Run Once, Do Not Run or Suspend.  I have the execution policy set on my machine to unrestricted so I am not sure why it is asking me...  I am working from within the ISE interface and recently upgraded to Powershell 3.0.  My machine is Windows 7.

     

    Thanks!

    Tony 

    Thursday, October 20, 2011 9:13 PM

Answers

All replies

  • Tony;

    How are you trying to run the scripts?

    I do this within a .ps1 script as

     

    c:\Scripts\Script1.ps1
    c:\Scripts\Script2.ps1
    c:\Scripts\Script3.ps1
    


    Works fine, no box popping up.

    Karl 


    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    Thursday, October 20, 2011 9:36 PM
  • Ah, I have a feeling I know what is causing my pain.  I want to launch it from a shared network location using UNC...  Either with IP nor Computername...  Any idea how to bypass this?

     

    Thanks!

    Thursday, October 20, 2011 9:53 PM
  • It sounds like your execution policy is not happy about those scripts. 

    Are they signed?


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Thursday, October 20, 2011 10:45 PM
  • No, I don't know how to sign them...  How would I go about doing that?
    Thursday, October 20, 2011 10:47 PM
  • Scott Hanselman has a nice article about it here:

    http://www.hanselman.com/blog/SigningPowerShellScripts.aspx


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    • Proposed as answer by Rich Prescott Thursday, October 20, 2011 11:00 PM
    • Marked as answer by IamMred Tuesday, October 25, 2011 2:31 AM
    Thursday, October 20, 2011 10:52 PM
  • Thanks!
    Thursday, October 20, 2011 10:56 PM