I have the main.ps1 file
where I am importing another file $dirpath\new.ps1
as below:
Import-module $dirpath\new.ps1 -force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
try {
$getval = invoke-command -cn $host -Credential $cred -ScriptBlock {
param($name)
get-myfunc $name
} -ArgumentList $name
} catch {
...
}
Both main.ps1 file
and new.ps1
are existing under the same directory - $dirpath.
The new.ps1
looks as below:
Function global:get-myfunc{
PARAM(
[Parameter(Mandatory=$true,Position=0)][STRING]$name
)
write-host "$name"
}
Now, the main.ps1 file
is throwing below error:
+ $getval = invoke-command -cn $host -Credential $cred -S ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (get-myfunc:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I have tried renaming new.ps1
as new.psm1
then importing module as Import-module $dirpath\new.psm1
but it is still failing with same error.
I am using poweshell 5