title: How to set variables in a new PowerShell object
body: <p>I'm trying to create a script to update Azure AD Privileged Identity Management which requires an object in the format below.</p>
  <p>I want to be able to pass variables to the object, e.g. '{&quot;required&quot;:$MFA}', where $MFA comes from a variable. I've tried the script block below but it doesn't recognize $MFA as a variable. Any ideas?</p>
  <pre class="lang-bsh prettyprint-override"><code># Set MFA Variable
  $MFA = &quot;True&quot;
  
  # Create object
  $myObject = [PSCustomObject]@{
      RuleIdentifer     = &quot;JustificationRule&quot;
      Setting = '{&quot;required&quot;:$MFA}'
  }
  
  #Output object
  write-host $myObject
  </code></pre>
  <p>The output just writes the $MFA text. It doesn't substitute $MFA for &quot;True&quot;</p>
  <pre><code>@{RuleIdentifer=JustificationRule; Setting={&quot;required&quot;:$MFA}}
  </code></pre>