title: Powershell write IF statement into a Variable
body: <p>I'm wanting to have an If/Else script that can write an output to a variable which I will use later on in the script.</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>if (!(Get-Module -ListAvailable -Name servermanager)) {
      Import-Module servermanager
  }
  
  $WinFeat = Get-WindowsFeature -Name telnet-client | Where installed
  if ($WinFeat -EQ $null) {
      Add-WindowsFeature telnet-client
  }
  </code></pre>
  
  <p>Essentially I was thinking that I could do something like this:</p>
  
  <pre><code>if (!(Get-Module -ListAvailable -Name servermanager)) {
      Import-Module servermanager
  } else {
      $alreadyModule
  }
  
  $WinFeat = Get-WindowsFeature -Name telnet-client | Where installed
  if ($WinFeat -EQ $null) {
      Add-WindowsFeature telnet-client
  } else {
      $alreadyFeature
  }
  
  if (($alreadyModule) -and ($alreadyFeature) {Write-Host "STUFF INSTALLED"}
  </code></pre>
  
  <p>That "stuff" will be used in an stdout that I will then use in an Ansible Playbook.</p>
  
  <p>So essentially I want to say IF this is already installed, AND that is already installed, then write STUFF INSTALLED to be used in Ansible... but I can't seem to figure out how to write a variable without it first starting with:</p>
  
  <pre><code>$alreadyModule = ....
  $alreadyFeature = ....
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>