Hi Everybody.
I'm Using Powershell for about 1 year now as a System Admin.
I've written a lot of brief functions, its a kind of admin-toolbox.
What I don't realy understand is the "dot-sourcing" mechanism.
- Are the "dot-sourced" functions loaded into ram ?
- If yes, is there any incidence on performances ?
- Is only a link to the functions loaded ?
Here are some options I have listed to organize my functions.
Could you please comment and give the Pros and Cons in regard of best performances (especially powershell loading time).
1°/ Write The functions into my profile.ps1
2°/ Write the functions into one (or several) ps1 file(s) and "dot-source" from my profile.
3°/ Create a Module and load it from my profile.
And additional, for those 3 options which is the best way to proceed :
- Put the functions into script ( profile, dot-sourced.ps1, module)
Example : ( a short function that i'm using in many scriots to check if remote host is available before
<br>function f-IfPing {<br> If ( $args[0] -ne $null) {<br> $Global:Ping = (New-Object System.Net.NetworkInformation.Ping).Send($args[0],10)<br> If ( $Ping.Status -eq [System.Net.NetworkInformation.IPStatus]::Success ) { $true }<br> Else {$false} }<br> Else { $false} <br> }<br> - Put the code into isolated scripts that will be called by functions in ( profile, dot-sourced.ps1, module )
Example :
<br>function F-IfPing { Path\F-Ifping.ps1 $args[0] }<br> <br> Path\F-Ifping.ps1 : <br> If ( $args[0] -ne $null) {<br> $Global:Ping = (New-Object System.Net.NetworkInformation.Ping).Send($args[0],10)<br> If ( $Ping.Status -eq [System.Net.NetworkInformation.IPStatus]::Success ) { $true }<br> Else {$false} }<br> Else { $false } <br> I hope I wasn't too long, and that my english is good enough to make my questions clear ;-)