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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