As per the image showing below, I have two PS1 script files.
main.ps1
(from where we call the call.ps1 function)call.ps1
Now, check the below SS for reference of structure - Both are on same Folder.
Now, When we call the main.ps1
1st time in New Powershell window it's working fine. (see blow)
Now the real issue is, If we call the same function again 2nd time it's not working and giving an error. (see below)
Am I missing something or understanding the things incorrectly? - Or this is not the way to call the PS1 from another PS1 file?
Surprisingly, If I close the existing Terminal and open New Terminal it works fine for the 1st time..!!!
Anyone has any clue what's wrong we're doing??
CodePudding user response:
Someone might write this better then me.
You need to rename call.ps1
to call.psm1
Then change the code in main.ps1
to the following
Import-Module '.\call.psm1'
callingthefunction
Also in your main.ps1
you used './call.ps1'
the slash direction is wrong. Look at my code above.
For more information about modules which is what you are creating. Please read.