PwSh.Crescendo.bcdedit.psm1

# Module created by Microsoft.PowerShell.Crescendo
class PowerShellCustomFunctionAttribute : System.Attribute {
    [bool]$RequiresElevation
    [string]$Source
    PowerShellCustomFunctionAttribute() { $this.RequiresElevation = $false; $this.Source = "Microsoft.PowerShell.Crescendo" }
    PowerShellCustomFunctionAttribute([bool]$rElevation) {
        $this.RequiresElevation = $rElevation
        $this.Source = "Microsoft.PowerShell.Crescendo"
    }
}

function BCDParseEnumId {
    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    Param (
        [Parameter(Mandatory = $true, ValueFromPipeLine = $true)]$cmdResults
    )
    Begin {
        Write-EnterFunction
    }

    Process {
        $textBlocks = ($cmdResults | Out-String) -split "`r`n`r`n"
        $entry = [ordered]@{}
        # it seems that real keys/value pair all start with lowercase char
        # titles starts with uppercase
        $textBlocks | select-string "^[a-z]" | ForEach-Object {
            $key = ($_ -Split " +")[0]
            $value = ($_ -Split " +",2)[1]
            $entry.Add($key,$value)
        }
        return [PSCustomObject]$entry
    }

    End {
        Write-LeaveFunction
    }
}


function Get-BCDEnum
{
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
[CmdletBinding(DefaultParameterSetName='Default')]

param(
[ValidateSet('ACTIVE','FIRMWARE', 'BOOTAPP', 'BOOTMGR', 'OSLOADER', 'RESUME', 'INHERIT', 'ALL')]
[Parameter(ParameterSetName='ByType')]
[string]$Type,
[Parameter(ParameterSetName='ById')]
[string]$Id,
[Parameter(ParameterSetName='Default')]
[Parameter(ParameterSetName='ByType')]
[Parameter(ParameterSetName='ById')]
[string]$Store,
[Parameter(ParameterSetName='Default')]
[Parameter(ParameterSetName='ByType')]
[Parameter(ParameterSetName='ById')]
[switch]$DisplayGUID
    )

BEGIN {
    $__PARAMETERMAP = @{
         Type = @{
               OriginalName = '/enum'
               OriginalPosition = '0'
               Position = '2147483647'
               ParameterType = 'string'
               ApplyToExecutable = $False
               NoGap = $False
               DefaultMissingValue = 'ACTIVE'
               }
         Id = @{
               OriginalName = '/enum'
               OriginalPosition = '0'
               Position = '2147483647'
               ParameterType = 'string'
               ApplyToExecutable = $False
               NoGap = $False
               DefaultMissingValue = 'ACTIVE'
               }
         Store = @{
               OriginalName = '/store'
               OriginalPosition = '0'
               Position = '2147483647'
               ParameterType = 'string'
               ApplyToExecutable = $False
               NoGap = $False
               }
         DisplayGUID = @{
               OriginalName = '/v'
               OriginalPosition = '0'
               Position = '2147483647'
               ParameterType = 'switch'
               ApplyToExecutable = $False
               NoGap = $False
               }
    }

    $__outputHandlers = @{
        ById = @{ StreamOutput = $False; Handler = 'BCDParseEnumId' }
    }
}

PROCESS {
    $__boundParameters = $PSBoundParameters
    $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name
    $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_})
    $__commandArgs = @()
    $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)})
    if ($__boundParameters["Debug"]){wait-debugger}
    foreach ($paramName in $__boundParameters.Keys|
            Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}|
            Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) {
        $value = $__boundParameters[$paramName]
        $param = $__PARAMETERMAP[$paramName]
        if ($param) {
            if ($value -is [switch]) {
                 if ($value.IsPresent) {
                     if ($param.OriginalName) { $__commandArgs += $param.OriginalName }
                 }
                 elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue }
            }
            elseif ( $param.NoGap ) {
                $pFmt = "{0}{1}"
                if($value -match "\s") { $pFmt = "{0}""{1}""" }
                $__commandArgs += $pFmt -f $param.OriginalName, $value
            }
            else {
                if($param.OriginalName) { $__commandArgs += $param.OriginalName }
                $__commandArgs += $value | Foreach-Object {$_}
            }
        }
    }
    $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null}
    if ($__boundParameters["Debug"]){wait-debugger}
    if ( $__boundParameters["Verbose"]) {
         Write-Verbose -Verbose -Message $env:TEMP/bcdedit.exe
         $__commandArgs | Write-Verbose -Verbose
    }
    $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName]
    if (! $__handlerInfo ) {
        $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present
    }
    $__handler = $__handlerInfo.Handler
    if ( $PSCmdlet.ShouldProcess("$env:TEMP/bcdedit.exe $__commandArgs")) {
    # check for the application and throw if it cannot be found
        if ( -not (Get-Command -ErrorAction Ignore "$env:TEMP/bcdedit.exe")) {
          throw "Cannot find executable '$env:TEMP/bcdedit.exe'"
        }
        if ( $__handlerInfo.StreamOutput ) {
            & "$env:TEMP/bcdedit.exe" $__commandArgs | & $__handler
        }
        else {
            $result = & "$env:TEMP/bcdedit.exe" $__commandArgs
            & $__handler $result
        }
    }
  } # end PROCESS

<#
.SYNOPSIS
Lists entries in the store.
 
.DESCRIPTION
Lists entries in the store.
 
.PARAMETER Type
Specifies the type of entries to be listed. <type> can be one of the following: ACTIVE All entries in the boot manager display order. This is the default. FIRMWARE All firmware applications. BOOTAPP All boot environment applications. BOOTMGR The boot manager. OSLOADER All operating system entries. RESUME All resume from hibernation entries. INHERIT All inherit entries. ALL All entries.
 
 
.PARAMETER Id
Specifies the identifier of the entry to be listed. If anidentifier is provided, then only the specified object will belisted. For information about identifiers, run "bcdedit /? ID".
 
 
.PARAMETER Store
Specifies the store to be used. If this option is notspecified, the system store is used. For more information,run 'bcdedit /? store'.
 
 
.PARAMETER DisplayGUID
Displays entry identifiers in full, rather than usingnames for well-known identifiers.
 
 
 
.EXAMPLE
PS> Get-BCDEnum
 
Get a list of active BCD entries
Original Command: bcdedit.exe /enum
 
 
#>

}


function BCDParseEnumItems {
    [CmdletBinding()]
    [OutputType([array])]
    Param (
        [Parameter(Mandatory = $true, ValueFromPipeLine = $true)]$cmdResults
    )
    Begin {
        Write-EnterFunction
    }

    Process {
        ($cmdResults | Out-String) -Split "`r`n" | ForEach-Object { Write-Devel $_ }
        $ids = @()
        $ids = $cmdResults | select-string "^identifier" | ForEach-Object { ($_ -Split " +")[1] }
        return $ids
    }

    End {
        Write-LeaveFunction
    }
}


function Get-BCDListItems
{
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
[CmdletBinding(DefaultParameterSetName='DisplayName')]

param(
[Parameter(ParameterSetName='DisplayId')]
[Parameter(ParameterSetName='DisplayName')]
[switch]$All,
[Parameter(ParameterSetName='DisplayId')]
[switch]$Id,
[Parameter(ParameterSetName='DisplayName')]
[switch]$Name
    )

BEGIN {
    $__PARAMETERMAP = @{
         All = @{
               OriginalName = '/enum all'
               OriginalPosition = '0'
               Position = '2147483647'
               ParameterType = 'switch'
               ApplyToExecutable = $False
               NoGap = $False
               }
         Id = @{
               OriginalName = '/v'
               OriginalPosition = '0'
               Position = '2147483647'
               ParameterType = 'switch'
               ApplyToExecutable = $False
               NoGap = $False
               }
         Name = @{
               OriginalName = ''
               OriginalPosition = '0'
               Position = '2147483647'
               ParameterType = 'switch'
               ApplyToExecutable = $False
               NoGap = $False
               }
    }

    $__outputHandlers = @{
        Default = @{ StreamOutput = $False; Handler = 'BCDParseEnumItems' }
    }
}

PROCESS {
    $__boundParameters = $PSBoundParameters
    $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name
    $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_})
    $__commandArgs = @()
    $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)})
    if ($__boundParameters["Debug"]){wait-debugger}
    foreach ($paramName in $__boundParameters.Keys|
            Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}|
            Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) {
        $value = $__boundParameters[$paramName]
        $param = $__PARAMETERMAP[$paramName]
        if ($param) {
            if ($value -is [switch]) {
                 if ($value.IsPresent) {
                     if ($param.OriginalName) { $__commandArgs += $param.OriginalName }
                 }
                 elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue }
            }
            elseif ( $param.NoGap ) {
                $pFmt = "{0}{1}"
                if($value -match "\s") { $pFmt = "{0}""{1}""" }
                $__commandArgs += $pFmt -f $param.OriginalName, $value
            }
            else {
                if($param.OriginalName) { $__commandArgs += $param.OriginalName }
                $__commandArgs += $value | Foreach-Object {$_}
            }
        }
    }
    $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null}
    if ($__boundParameters["Debug"]){wait-debugger}
    if ( $__boundParameters["Verbose"]) {
         Write-Verbose -Verbose -Message $env:TEMP/bcdedit.exe
         $__commandArgs | Write-Verbose -Verbose
    }
    $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName]
    if (! $__handlerInfo ) {
        $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present
    }
    $__handler = $__handlerInfo.Handler
    if ( $PSCmdlet.ShouldProcess("$env:TEMP/bcdedit.exe $__commandArgs")) {
    # check for the application and throw if it cannot be found
        if ( -not (Get-Command -ErrorAction Ignore "$env:TEMP/bcdedit.exe")) {
          throw "Cannot find executable '$env:TEMP/bcdedit.exe'"
        }
        if ( $__handlerInfo.StreamOutput ) {
            & "$env:TEMP/bcdedit.exe" $__commandArgs | & $__handler
        }
        else {
            $result = & "$env:TEMP/bcdedit.exe" $__commandArgs
            & $__handler $result
        }
    }
  } # end PROCESS

<#
.SYNOPSIS
Lists entries in the store.
 
.DESCRIPTION
Lists entries in the store.
 
.PARAMETER All
 
 
 
.PARAMETER Id
 
 
 
.PARAMETER Name
 
 
 
 
.EXAMPLE
PS> Get-BCDListItems
 
Get a list of BCD entries identifiers
Original Command: bcdedit.exe
 
 
#>

}


function BCDParseCreate {
    [CmdletBinding()]
    [OutputType([String])]
    Param (
        [Parameter(Mandatory = $true, ValueFromPipeLine = $true)]$cmdResults
    )
    Begin {
        Write-EnterFunction
    }

    Process {
        return $string
    }

    End {
        Write-LeaveFunction
    }
}


function New-BCDStore
{
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Low',DefaultParameterSetName='Default')]

param(    )

BEGIN {
    $__PARAMETERMAP = @{}
    $__outputHandlers = @{
        Default = @{ StreamOutput = $False; Handler = 'BCDParseCreate' }
    }
}

PROCESS {
    $__boundParameters = $PSBoundParameters
    $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name
    $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_})
    $__commandArgs = @()
    $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)})
    if ($__boundParameters["Debug"]){wait-debugger}
    $__commandArgs += '/createstore'
    foreach ($paramName in $__boundParameters.Keys|
            Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}|
            Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) {
        $value = $__boundParameters[$paramName]
        $param = $__PARAMETERMAP[$paramName]
        if ($param) {
            if ($value -is [switch]) {
                 if ($value.IsPresent) {
                     if ($param.OriginalName) { $__commandArgs += $param.OriginalName }
                 }
                 elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue }
            }
            elseif ( $param.NoGap ) {
                $pFmt = "{0}{1}"
                if($value -match "\s") { $pFmt = "{0}""{1}""" }
                $__commandArgs += $pFmt -f $param.OriginalName, $value
            }
            else {
                if($param.OriginalName) { $__commandArgs += $param.OriginalName }
                $__commandArgs += $value | Foreach-Object {$_}
            }
        }
    }
    $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null}
    if ($__boundParameters["Debug"]){wait-debugger}
    if ( $__boundParameters["Verbose"]) {
         Write-Verbose -Verbose -Message $env:TEMP/bcdedit.exe
         $__commandArgs | Write-Verbose -Verbose
    }
    $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName]
    if (! $__handlerInfo ) {
        $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present
    }
    $__handler = $__handlerInfo.Handler
    if ( $PSCmdlet.ShouldProcess("$env:TEMP/bcdedit.exe $__commandArgs")) {
    # check for the application and throw if it cannot be found
        if ( -not (Get-Command -ErrorAction Ignore "$env:TEMP/bcdedit.exe")) {
          throw "Cannot find executable '$env:TEMP/bcdedit.exe'"
        }
        if ( $__handlerInfo.StreamOutput ) {
            & "$env:TEMP/bcdedit.exe" $__commandArgs | & $__handler
        }
        else {
            $result = & "$env:TEMP/bcdedit.exe" $__commandArgs
            & $__handler $result
        }
    }
  } # end PROCESS

<#
 
 
.DESCRIPTION
This command created a new empty boot configuration data store. The
created store is not a system store.
 
<filename> Specifies the filename of the boot configuration data
                store. If the filename contains spaces, it must be
                enclosed in quotation marks ("").
 
.EXAMPLE
PS> New-BCDStore
 
Creates the specified store file
Original Command: bcdedit /createstore C:\DATA\BCD
 
 
#>

}