Created
October 25, 2021 23:32
-
-
Save Diagg/f4b696aa5cd482f672477dffa0712d87 to your computer and use it in GitHub Desktop.
Parse BCDedit enumation to a Powershell Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 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