I think you’re probably trying a few random stuff and getting stuck :).
The Import-Module command does expect a .PSM1 file. While Vern is right in that module files can be located in specific locations for auto-loading, you can also manually specify a path when you load them. However, a path like “.\get-freespace.psm1″ refers to the current directory. The “current” directory has to be set as the working directory in Task Scheduler.
It might be better to have your task load the module, using Import-Module, but providing a COMPLETE, absolute path (starting with a drive letter) to the module file.
But here’s where you’re missing something:
.\get-freespace.ps1 -computers c:\scripts\computers.txt -To jake@test.local -From schedtask@test.local -smtpserver mail.test.local
That is running a SCRIPT called Get-Freespace.ps1, and passing the parameters TO THAT SCRIPT. In other words, the expectation there is that the script just contains commands, and not a function. It seems like that might be the best way for you to do this. In other words, I’m not sure you need a function (or a module). I think you just need a script. I would expect the top of what script to contain a Param() block, but NOT the “function” keyword.
But again, when you run the script, provide an absolute path to it, not a relative path, because when the task runs, Task Scheduler won’t necessarily set the same working directory.
Does that help?