Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a ps1 script in which I define 2 functions as such:

function Invoke-Sql([string]$query) {
  Invoke-Sqlcmd -ServerInstance $Server -Database $DB -User $User -Password $Password -Query $query

function Get-Queued {
  Invoke-Sql "Select * From Comment where AwaitsModeration = 1"

I then call the ps1 file by typing it in (it's in a folder in the path, and autocompletion works)

However, I cannot start using the functions. I am confused, because when I copy / paste the functions into the console, all is fine and they work. I also have a function defined in my profile, and it works. Where am I thinking wrong, why doesn't it work what I'm trying to do?

share|improve this question
up vote 4 down vote accepted

In order for the functions to be available, you need to "dot source" the script. "Dot Sourcing" runs the script in the current scope.

To "dot source" a script you put a period then a space and then the full or relative path to the script.


. ./myscript.ps1
share|improve this answer

Check out this post about running powershell scripts from the command line.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.