title: PowerShell project, where to put global settings?
body: <p>We are building a bigger project with PowerShell (a collection of scripts/functions that helps us setup some SharePoint environments/tenants).</p>
  
  <p>A lot of the functions should reuse settings that are stored in a single, central place.</p>
  
  <p>I couldn't find a "best practice" of how such a settings file/location should be best created and structured.</p>
  
  <p>My idea is to store global settings in a separate file (a module file), for example <strong>Settings.psm1</strong> with content like this:</p>
  
  <pre><code># Set vars
  $global:scriptEnvironment = "SP2016HOSTINGDEV"
  $global:logFileName = "z_Migration_to_SP2016.log"
  $global:languageMapping = @{
      "en-US" = 1;
      "de-DE" = 2;
  }
  $global:oldWsps = @(
      [WspFile]@{ Filename = "comapany.solution.wsp"; IsDeployable = $true; IsGloballyDeployable = $false; FullTrustBinDeployment = $false },
      [WspFile]@{ Filename = "company.solution2.server.wsp"; IsDeployable = $true; IsGloballyDeployable = $false; FullTrustBinDeployment = $false }
  )
  ...
  </code></pre>
  
  <p>And in the other modules/scripts I then could always include those settings like this:</p>
  
  <pre><code># Set vars
  $scriptDirectory = Split-Path -parent $PSCommandPath
  
  # Module import
  Import-Module (Join-Path $scriptDirectory Settings.psm1) -Force -ErrorAction Stop
  Import-Module (Join-Path $scriptDirectory Functions.psm1) -Force -ErrorAction Stop
  
  # Functions
  ...
  </code></pre>
  
  <p>So this would make me able to use the global settings like this in the functions inside other script files:</p>
  
  <pre><code>Function WriteLog
  {
      param
      (
          [System.String]$LogString = "",
          [System.String]$LogLevel = ""
      )
      WriteLogToPath -LogFileName $global:logFileName -LogString $LogString -LogLevel $LogLevel
  }
  </code></pre>
  
  <p>Is this a good approach? Or shouldn't I use module files for this and if not what kind of files should I use instead?</p>