Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Functionality wise I think there are a couple of ways you could improve your script. </p> <p>The first is that your script is dependent upon the name of the script not changing. While I don't think it's likely you'll change the name of this script, you never know what mood you'll be in a few years from now. Instead why not just calculate the name of the script dynamically.</p> <pre><code>$scriptName = split-path -leaf $MyInvocation.MyCommand.Definition </code></pre> <p>The next problem is that I believe you're split function will fail if you ever place the directory in a path which contains a space. It will cause a path like "c:\foo bar\baz.ps1" to appear as "c:\foo", "bar\baz.ps1". Much better to remove the split and just use the enumeration by the get-childitem command. </p> <p>Also you are taking a dependency on the current path being the path containing the scripts. You should either make that an explicit parameter or use the path containing the allFunctions.ps1 file (i prefer the latter)</p> <p>Here is the updated version I would use.</p> <pre><code>$scriptName = split-path -leaf $MyInvocation.MyCommand.Definition $rootPath = split-path -parent $MyInvocation.MyCommand.Definition $scripts = gci -re $rootPath -in *.ps1 | ?{ $_.Name -ne $scriptName } foreach ( $item in $scripts ) { . $item.FullName } </code></pre> <p>From a security standpoint you have to consider the possibility that a malicious user adds a bad script into the target directory. If they did so it would be executed with your allFunctions.ps1 file and could do damage to the computer. But at the point the malicious user has access to your file system, it's likely they could do the damage without the help of your script so it's probably a minor concern. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload