now it is three years since I started looking at SharePoint (2007). I had just finished my masters and had no idea of what SharePoint was (had never done any web development either) so i was blank. Have after three years worked on ASP.net projects and SharePoint projects. So I'm thinking it is time for me to blog about my SharePoint findings. So here we go.
Today I needed to call another script file in the same folder as the main script. After a little searching on the web I found "$MyInvocation.MyCommand.Path". "$MyInvocation.MyCommand.Path" returns the path to the current script, With that I was able to get the current folder using Get-Item. This is my test scripts: ToRun.ps1: Write-Host $MyInvocation.MyCommand.Path $scriptDirectory = (Get-Item $MyInvocation.MyCommand.Path).DirectoryName $scriptName = "HelloWorld.ps1" Write-Host calling $scriptName in $scriptDirectory & ($scriptDirectory + '\' + $scriptName) HelloWorld.ps1: Write-Host "Hello word" After running the script the output was: calling HelloWorld.ps1 in C:\scriptFun Hello word Simple but useful.
Comments