Write-DellBIOSPassword.ps1

Function Write-DellBIOSPassword {
<#
  .Synopsis
    Writes a Dell BIOS password from secure string storage
  .Description
    Writes a DellBIOS password to System.Security.SecureString in the local app directory of the user.
  .Example
    Write-DellBIOSPassword
  .Example
    $DellBIOSCredential = Write-DellBIOSPassword
  .Example
    $SecureStringPwd = Read-Host -AsSecureString
    Write-DellBIOSPassword –Password $SecureStringPwd
  .Example
    Write-DellBIOSPassword [[-FilePath] <String>] [[-Key] <String>] [[-Hint] <String>] [-Password] <SecureString> [<CommonParameters>]
    #>


[CmdletBinding()]
Param (
  [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,ValueFromPipeline=$true, position=0, HelpMessage="Path to Password File")] [string] $FilePath,
  [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,ValueFromPipeline=$false, position=1, HelpMessage="An ASCII Key of 128,196 of 256 Length")] [byte []] $Key,    
  [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,ValueFromPipeline=$false, position=2, HelpMessage="Password Hint")] [string] $Hint, 
  [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,ValueFromPipeline=$false, position=5, HelpMessage="DellBIOS Password")] [System.Security.SecureString] $Password
 ) 


PROCESS {

    if ([string]::IsNullOrEmpty($FilePath))
    {
        $FilePath = (Get-DellBIOSPasswordPath).DellBIOSPwdFilePath
    }
    
    if ( (test-path $FilePath) -eq $false)
    {
        $fileItem = new-item -path $FilePath -itemtype file -force
    }

    [Xml]$xml="<Credential><Password></Password><Encryption>DAPI</Encryption></Credential>"

    if ([string]::IsNullOrEmpty($Key))
    {
        $xml.Credential.Password= (ConvertFrom-SecureString -SecureString $Password).ToString()
        $xml.Credential.Encryption="DPAPI"
        Set-Content $FilePath $xml.OuterXml
    }
    else
    {        
        $xml.Credential.Password= (ConvertFrom-SecureString -SecureString $Password -Key $Key).ToString()
        $xml.Credential.Encryption="Rijndael"
        Set-Content $FilePath $xml.OuterXml
    }

  }#EndProcess
}#end Function


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