Home > SharePoint > How to write PowerShell code part 3 (calling external script)

How to write PowerShell code part 3 (calling external script)

In this post, I’d like to show you how to calling external script from a PowerShell script. I’d like to use the site creation script as an example. You can download script here.

1. To call the external script, you need to first to grab the script path. You can do so by calling $scriptPath = Split-Path $myInvocation.MyCommand.Path to grab the current script path. You can then use this to build the path for your external script path.

$scriptPath = Split-Path $myInvocation.MyCommand.Path
$ExternalScript=$scriptPath+"\CreateSiteCollection.ps1"
$configurationXmlPath=$scriptPath+"\SiteCollection.xml"
[xml] $configurationXml=Get-Content $configurationXmlPath
& "$ExternalScript" $configurationXml
Write-Host

2.If you like to pass in any parameters , you need to define your script parameters in param () at the top of the script and separate each parameter by a comma (,) and when calling the method you do not need comma (,) to separate each parameter.

#Pass in the Parameters.
param ([xml] $xmlinput)

How to write PowerShell code part 1
How to write PowerShell code part 2
How to write PowerShell code part 3
How to write PowerShell code part 4

Advertisements
Categories: SharePoint Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: