Page 1 of 1

calling function in external file

Posted: Fri Sep 28, 2018 10:18 am
by Domtar
hi all,

aside from dot sourcing, is there some oter way to call a function inside an external file?

I know about . .\myfile.ps1, I also know about modules, but in my case, both these options aren't doing what I want.

The issue is that I need to force a script to be launched in the 64-bit system from a SCCM 32-bit client. I want to launch like this;

start-process "C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe" -arg...

using dot sourcing won't enforce the bitness.

thanks!

Re: calling function in external file

Posted: Fri Sep 28, 2018 10:25 am
by jvierra
The version of PowerShell enforces the bitness. This has nothing to do with the script or function calls. Functions always run in the architecture calling them.
Only dot sourcing will work

Dot sourcing is not what you posted. That is just loafing from the current folder. In a call like this you should always use the full path

Dot sourcing only a file will never execute any function.

Re: calling function in external file

Posted: Fri Sep 28, 2018 10:32 am
by Domtar
Well, looks like I badly explained my situation.

In SCCM, when you want to deploy something to a bunch of computers, you create a "package" that is sent to those computers. The package has a command line to execute something.

On the computers, there is an agent that receives those instructions and proceed with the required installation. Thanks to Microsoft, the SCCM client in question is 32-bit, so our scripts are launched in that bitness. Now, if I use the command line to start the process of PowerShell.exe from c:\windows\sysnative..., Windows will comply and launch the required script in 64-bit on a 64-bit computer.

We have an issue with this because some scripts require to be executed in the 64-bit system even when launched from the 32-bit SCCM client. My way of going around it is to have the main wrapper script call an external script by enforcing the 64-bit system.

I hope this makes more sense now.

thanks!

Re: calling function in external file

Posted: Fri Sep 28, 2018 10:47 am
by Domtar
In other words;

I can easily start another script each time with that sysnative thing but that means I would have to create a script for each function and that is what I want to avoid.

any hint?

Re: calling function in external file

Posted: Fri Sep 28, 2018 11:14 am
by jvierra
Your question is far too vague to answer.

You can create a file with many functions and call them as needed.