To include a Auto.ps1 file in another main.ps1 , you must know the absolute path of Auto.ps1 , do not allow relative routes.
However, you can calculate the route from the command invoked:
# Obtener el directorio base donde están los scripts a partir del que lo invoca
$base = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
# Incluir las referencias necesarias
. ($base + ".\Auto.ps1")
So, your commands can be in a directory structure like
MisScripts\
Util\
util.ps1
Extra\
extra.ps1
actualizar.ps1
listar.ps1
then, to include util.ps1 from list.ps1 you would write in the latter
. ($base + ".\Util\util.ps1")
A complete example could be to leave in the following structure
Ejemplo\
Util\
Auto.ps1
main.ps1
where Auto.ps1 contains
Class Auto {
[string] $Marca
[string] $Color
Auto ([string] $m,[string] $c) {
$this.Color = $c
$this.Marca = $m
}
[void] Report() {
Write-Host ("AUTO: " + $this.Marca + " (" + $this.Color + ")")
}
}
and main.ps1 contains
# Obtener el directorio base donde están los scripts a partir del que lo invoca
$base = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
# Incluir las referencias necesarias
. ($base + ".\Util\Auto.ps1")
[Auto]::new("Audi", "Azul").Report()
then, when calling from anywhere main.ps1 you get
C:\Users\josejuan>powershell d:\datos\tmp\main.ps1
AUTO: Audi (Azul)
C:\Users\josejuan>