header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

How do I call a Powershell script within a script?
Last Post 24 Apr 2008 07:49 PM by smurawski. 6 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
09 Jan 2008 06:16 PM  

I'm using PrimalScript and am executing the script from the script pull-down menu itm.  My main script is trying to call another script but It does not like my syntax. 

The following line of code:

Highlight-Syntax.ps1 ./TestServices.ps1 -Linenumbers | Out-File test3.html

Produces the following error:

ERROR: The term 'Highlight-Sytax.ps1' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.
ERROR: At line:598 char:20
ERROR: + Highlight-Sytax.ps1 <<<< ./TestServices.ps1 -Linenumbers | Out-File test3.html

*** PowerShell Script finished. ***

 

What am I doing wrong?

My blog: http://blogs.powershellcentral.com/kscriss/
bsonposhUser is Offline
Basic Member
Basic Member
Posts:393
Avatar

--
09 Jan 2008 06:23 PM  
you have to path the script

C:\pathtoscript\Highlight-Syntax.ps1
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
09 Jan 2008 06:26 PM  

Thanks, I'll give that a try.

I think:

$results = ./Highlight-Sytax.ps1 ./TestServices.ps1 -Linenumber
$results | out-file test3.htm

would work too.

My blog: http://blogs.powershellcentral.com/kscriss/
kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
09 Jan 2008 06:33 PM  

How do I handle spaces in the path name?

My blog: http://blogs.powershellcentral.com/kscriss/
kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
09 Jan 2008 06:41 PM  

Oh, I see.

I did a get-location and it was other than expected.

After doing a set-location calling the script from withing the script worked as I originally thought it would.

My blog: http://blogs.powershellcentral.com/kscriss/
KarthikeyanUser is Offline
New Member
New Member
Posts:1
Avatar

--
24 Apr 2008 07:14 PM  
I got 2 *.ps1 scripts
Master.ps1 - which has couple of functions
Test.ps1 - test script file which calls Master.ps1
both are in same directory and I call the .\Master.ps1 file and it works fine, but the functions are not exposed.
but if I execute those functions in the PowerShell editor its exposed.
Cant I run a ShellScript within a Script file.

Can someone please throw some light on my query
smurawskiUser is Offline
New Member
New Member
Posts:46

--
24 Apr 2008 07:49 PM  

Karthikeyan ,

If you would like to expose the functions and variables in the Master.ps1 script, you will need to dot source the script.
That will work as long as your calling script is in the same directory as the Master.ps1.

. ./Master.ps1



It might be more robust to use

$path = $MyInvocation.MyCommand.Path | Split-Path -Parent
$script = 'Master.ps1"
. &(Join-Path $path $script)
Steven Murawski
Co-Host - Mind of Root (www.mindofroot.com)
Host - PowerShell Basics (powershell-basics.com)
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer