title: System.Security.SecureString error when executing Install-ADDSForest
body: <p>I struggling a bit with Install-ADDSForest. I try to automate my AD creation for my home lab and the process terminated with the message &quot;Install-ADDSForest : Cannot bind parameter 'SafeModeAdministratorPassword'. Cannot convert the &quot;Pa$$w0rd&quot; value of type &quot;System.String&quot; to type
  &quot;System.Security.SecureString&quot;.&quot;
  How I can feed the command with the correct syntax?</p>
  <p>Thank you</p>
  <pre><code>$XML = [xml]@'
  &lt;Test&gt;
      &lt;Lab Active = &quot;True&quot; &gt;
          &lt;Task Name = &quot;DomainController&quot; Active = &quot;True&quot; Order = &quot;1&quot; ControllerName = &quot;SRVDC01&quot; DomainName = &quot;&amp;quot;LAB.lcl&amp;quot;&quot; CreateDnsDelegation = &quot;$False&quot; DatabasePath = &quot;&amp;quot;C:\Windows\NTDS&amp;quot;&quot; DomainMode = &quot;&amp;quot;WinThreshold&amp;quot;&quot; DomainNetbiosName = &quot;&amp;quot;LAB&amp;quot;&quot; ForestMode = &quot;&amp;quot;WinThreshold&amp;quot;&quot; InstallDns = &quot;$True&quot; LogPath= &quot;&amp;quot;C:\Windows\NTDS&amp;quot;&quot; NoRebootOnCompletion= &quot;$True&quot; SafeModeAdministratorPassword= &quot;UGEkJHcwcmQ=&quot; SysvolPath= &quot;&amp;quot;C:\Windows\SYSVOL&amp;quot;&quot; Force = &quot;$True&quot; /&gt;
      &lt;/Lab&gt;
  &lt;/Test&gt;
  '@
  Function Decode-Password() {
  
      PARAM(
  
          [Parameter(Mandatory=$True)]
          [String]$EncPassword = &quot;&quot;
          
      )
      
      BEGIN {}
      
      PROCESS {
  
          $Temp = [system.convert]::FromBase64String($EncPassword)
          $DecPassword = [system.text.encoding]::UTF8.Getstring($temp)
          
      }
      
      END { Return $DecPassword } 
      
  }
  
  If($($XML.Test.Lab.Active) -eq &quot;True&quot;) {
      ForEach($ActiveTask in $XML.Test.Lab.Task | Sort-Object Order | Where-Object { $_.Active -eq &quot;True&quot; }){
          Switch($ActiveTask.Name){
              DomainController {
                  If((Get-WindowsFeature | Where-Object { $_.Name -eq &quot;AD-Domain-Services&quot;}).Installstate -eq &quot;Available&quot;){
                      Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools -IncludeAllSubFeature
                  }
                  
                  &lt;#
                      - Default
                      - Windows Server 2003: “Win2003” or “2”
                      - Windows Server 2008: “Win2008” or “3”
                      - Windows Server 2008 R2: Win2008R2 or “4”
                      - Windows Server 2012: “Win2012” or “5”
                      - Windows Server 2012 R2: “Win2012R2” or “6”
                      - Windows Server 2016: “WinThreshold” or “7”
                  #&gt;
  
                  $DCParams = [string]::Empty
                  $Password = Decode-Password -EncPassword $($ActiveTask.SafeModeAdministratorPassword)
                  
                  If ($ActiveTask.DomainName -ne &quot;&quot;){
                      $DCParams += &quot;-DomainName &quot; + $ActiveTask.DomainName + ' `' + &quot;`r`n&quot;
                  }
                  If ($ActiveTask.CreateDnsDelegation -ne &quot;&quot;){
                      $DCParams += &quot;-CreateDnsDelegation &quot; + $ActiveTask.CreateDnsDelegation + ' `' + &quot;`r`n&quot;
                  }
                  If ($ActiveTask.DatabasePath -ne &quot;&quot;){
                      $DCParams += &quot;-DatabasePath &quot; + $ActiveTask.DatabasePath + ' `' + &quot;`r`n&quot;
                  }
                  If ($ActiveTask.DomainMode -ne &quot;&quot;){
                      $DCParams += &quot;-DomainMode &quot; + $ActiveTask.DomainMode + ' `' + &quot;`r`n&quot;
                  }
                  If ($ActiveTask.DomainNetbiosName -ne &quot;&quot;){
                      $DCParams += &quot;-DomainNetbiosName &quot; + $ActiveTask.DomainNetbiosName + ' `' + &quot;`r`n&quot;
                  }
                  If ($ActiveTask.ForestMode -ne &quot;&quot;){
                      $DCParams += &quot;-ForestMode &quot; + $ActiveTask.ForestMode + ' `' + &quot;`r`n&quot;
                  }
                  If ($ActiveTask.InstallDns -ne &quot;&quot;){
                      $DCParams += &quot;-InstallDns &quot; + $ActiveTask.InstallDns + ' `' + &quot;`r`n&quot;
                  }
                  If ($ActiveTask.LogPath -ne &quot;&quot;){
                      $DCParams += &quot;-LogPath &quot; + $ActiveTask.LogPath + ' `' + &quot;`r`n&quot;
                  }
                  If ($ActiveTask.NoRebootOnCompletion -ne &quot;&quot;){
                      $DCParams += &quot;-NoRebootOnCompletion &quot; + $ActiveTask.NoRebootOnCompletion + ' `' + &quot;`r`n&quot;
                  }
                  If ($ActiveTask.SafeModeAdministratorPassword -ne &quot;&quot;){
                      $DCParams += &quot;-SafeModeAdministratorPassword &quot; + '&quot;$Password&quot;' + ' `' + &quot;`r`n&quot;
                  }
                  If ($ActiveTask.SysvolPath -ne &quot;&quot;){
                      $DCParams += &quot;-SysvolPath &quot; + $ActiveTask.SysvolPath + ' `' + &quot;`r`n&quot;
                  }
  
                  If ($ActiveTask.Force -ne &quot;&quot;){
                      $DCParams += &quot;-Force &quot; + $ActiveTask.Force + ' `' + &quot;`r`n&quot;
                  }
  
                  #$x = $DCParams.TrimEnd(' `' + &quot;`r`n&quot;)
                  #$x
                  
  
                  $TrimDCParams = $DCParams.TrimEnd(' `' + &quot;`r`n&quot;)
                  $DCPromo = Invoke-Expression &quot;Install-ADDSForest ` $TrimDCParams&quot;
                  $DCPromo
  
              }
          }
      }
  }
  </code></pre>