# Controller Script & Module

**URL:** <https://forums.powershell.org/t/controller-script-module/13730>\
**Category:** PowerShell Help\
**Created:** [January 29, 2020, 8:19am UTC](https://forums.powershell.org/t/controller-script-module/13730 "2020-01-29T08:19:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason-mcmahan](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jason-mcmahan](https://forums.powershell.org/u/jason-mcmahan)\
**Post date:** [January 29, 2020, 8:19am UTC](https://forums.powershell.org/t/controller-script-module/13730/1 "2020-01-29T08:19:39Z")

</div>

Good day,

Could someone please help with a little guidance.

I recently built approximately 14 functions (12 public/ 2 private), however now i would like to create scheduled task on each server to execute the functions, then output the data to a sql database.

&nbsp;

I thought just create a control script to do this however i was wondering where i should store this?

Inside a module folder or separate?

Should i create a separate module imports the first module, creates a scheduled task on the server?

&nbsp;

Any suggestion or help would be greatly appreciated.

&nbsp;

Thank you

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [January 29, 2020, 9:50am UTC](https://forums.powershell.org/t/controller-script-module/13730/2 "2020-01-29T09:50:48Z")

</div>

IMHO, you should keep the module and the script separate. If you set up an internal repository, then you can host a module and script in a central location:

> **[Working with local PSRepositories - PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/gallery/how-to/working-with-local-psrepositories?view=powershell-7)**
>
> The PowerShellGet module support repositories other than the PowerShell Gallery. This article describes how to set up a local PowerShell repository.

> **[Powershell: Your first internal PSScript repository](https://powershellexplained.com/2017-05-30-Powershell-your-first-PSScript-repository/)**
>
> Setting up a basic internal repository for scripts and modules is surprisingly simple. I had no idea how easy this was for the longest time. If you are looking for ways to distribute your modules to others in your team, then you should consider this...

Then you can create a script on your worker servers that will automatically update the module and script during execution:

**Task 1: Get the latest script**

```
Install-Script...
```

**Task 2: Execute PS1, something like:**

```
Install-Module -Name MyModule -Repository MyRepository -Scope CurrentUser
Import-Module MyModule

$stuff = Get-MyModuleStuff

Invoke-SqlCmd ...
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:30pm UTC](https://forums.powershell.org/t/controller-script-module/13730/3 "2024-05-16T20:30:46Z")

</div>

Closed on May 16, 2024, 8:30pm UTC


