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

Posted by ybbest on YBBest See other posts from YBBest or by ybbest
Published on Sun, 13 May 2012 04:25:34 +0000 Indexed on 2012/06/22 3:26 UTC
Read the original article Hit count: 198

Filed under:
|

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)


© YBBest or respective owner

Related posts about sharepoint

Related posts about powershell