title: Powershell Passing Variable to Function
body: <p>I don't understand what is going on...</p>
  
  <p>In the <code>VerifyEmailSettings</code> function, the <code>$AdminEmailAddress</code> is one of many parameters i can pass to the ps command i am using.</p>
  
  <p>I want to be able to pass the paramater name, and value to other functions like below. However, when i pass this along, i get some odd results. As you can see in the results, trying to print the <code>$SettingName</code> in the <code>VerifyEmailSettings</code> function echos <code>AdminEmailAddress admin@superuser.com Verified, Same</code> instead of what i want... <code>AdminEmailAddress Verified, Same</code> The "admin@superuser.com is mixed in there somehow. Same happens with the <code>$SetName</code> in the <code>SetEmailSettings</code> functions.</p>
  
  <p>Thanks in advance!!</p>
  
  <pre class="lang-powershell prettyprint-override"><code>Write-Host "Starting Script"
  #Assigning Variables
  
  $AdminEmailAddress = "admin@superuser.com"
  $SmtpServer = "exchange.local"
  $FromEmailAddress = "fsrm@omg.com"
  
  
  If (GetInstallStatus){
  
  Write-Host "FSRM Installed, Skipping Install"
  Write-Host "Checking Email Settings"
  VerifyEmailSettings([string]"AdminEmailAddress",[string]$AdminEmailAddress)
  
  } else {
  
  Write-Host "FSRM Not Installed, Installing"
  Install-WindowsFeature –Name FS-Resource-Manager –IncludeManagementTools
  
      If (GetInstallStatus){
          Write-Host "FSRM Installed"
  
      } else {
          Write-Host "FSRM Error on Install, Halting"
          #halt here
      }
  
  } 
  
  function GetInstallStatus {
  $status = (Get-WindowsFeature -Name FS-Resource-Manager | ft Installed -autosize -hidetableheaders | out-string).trim();
  return $status
  }
  
  function VerifyEmailSettings([string]$SettingName, [string]$SettingData) {
  $Verify = (Get-FsrmSetting | Select-Object $SettingName | FT -autosize -hidetableheaders | Out-String).Trim()
  
  If ($Verify -eq $SettingData) {
      Write-Host $SettingName "Verified, Same"
      SetEmailSettings([string]$SettingName, [string]$SettingData)
  } Else {
      Write-Host $SettingName "Wrong, Updating"
      SetEmailSettings([string]$SettingName, [string]$SettingData)
  }
  
  }
  
  function SetEmailSettings([string]$SetName, [string]$SetData) {
  $SetName
  #Set-FsrmSetting $SetName $SetData
  }
  </code></pre>
  
  <p>Here is the results i get:</p>
  
  <pre><code>Starting Script
  FSRM Installed, Skipping Install
  Checking Email Settings
  AdminEmailAddress admin@superuser.com Verified, Same
  AdminEmailAddress admin@superuser.com
  </code></pre>