Skip to content

Instantly share code, notes, and snippets.

@Diagg
Created October 25, 2021 23:32
Show Gist options
  • Select an option

  • Save Diagg/f4b696aa5cd482f672477dffa0712d87 to your computer and use it in GitHub Desktop.

Select an option

Save Diagg/f4b696aa5cd482f672477dffa0712d87 to your computer and use it in GitHub Desktop.
Parse BCDedit enumation to a Powershell Object
## Parse BCDedit enumation to a Powershell Object
## By Diagg/OSDC - 26/10/2021
## Usage exemple: $Bcdedit|where Index -eq 0|select default
$ObjName = $null ; $Val = 0 ; $Index = 0 ; $Bcdedit = @()
$BcdString = bcdedit /v
$BcdString|Foreach {
If ($_.startswith('-'))
{
If ($ObjName -ne $null -and $ObjName.Name -ne $BcdString[$Val-1]){$Bcdedit += $ObjName}
$ObjName = [pscustomobject]@{'Name' = $BcdString[$Val-1] ; 'Index' = $Index}
$Index += 1
}
ElseIf ($ObjName -ne $null)
{
If ($_.Length -gt 0 -and (($BcdString.count -eq $val+1) -or -not $BcdString[$val+1].StartsWith("-")))
{
$string = ($_ -replace '[ ]{1,}',',').split(',')
$ObjName|Add-Member -MemberType NoteProperty -Name $String[0].trim() -Value $String[1].trim()
}
}
$Val += 1
}
$Bcdedit += $ObjName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment