Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How to create device/osdevice element into BCD file with powershell?

$
0
0

instance of BcdDeviceElement
{
Device = 
instance of BcdDeviceFileData
{
AdditionalOptions = "{9fc76b9c-f8ef-11e3-a7ec-7446a093755c}";
DeviceType = 4;
Parent = 
instance of BcdDevicePartitionData
{
AdditionalOptions = "";
DeviceType = 2;
Path = "\\Device\\HarddiskVolume1";
};
Path = "\\Recovery\\9fc76b9b-f8ef-11e3-a7ec-7446a093755c\\Winre.wim";
};
ObjectId = "{9fc76b9b-f8ef-11e3-a7ec-7446a093755c}";
StoreFilePath = "\\??\\C:\\bcd.bak";
Type = 285212673;
};

I get above information from existed device/osdevice element, but I tried to add the same element into another Windows boot loader element, but I can't.
Would you please help me to fix it? thanks a lots.

$server='.'

$locator = New-Object -ComObject WbemScripting.SWbemLocator
$locator.Security_.Privileges.AddAsString('SeBackupPrivilege')
$locator.Security_.Privileges.AddAsString('SeRestorePrivilege')
$wmi = $locator.ConnectServer($server,'root\wmi')
$class = $wmi.Get("BcdStore")

$inparams=$class.Methods_.Item('OpenStore').InParameters.SpawnInstance_()
$inparams.Properties_.Item('File').Value='c:\bcd.bak'
$outParams=$class.ExecMethod_('OpenStore',$inparams)

if($outParams.Properties_.Item('ReturnValue').Value)
{

    Write-Host 'Opened default store successful' -ForegroundColor green
    $store=$outParams.Properties_.Item('Store').Value

    $inparams=$store.Methods_.Item('CreateObject').InParameters.SpawnInstance_()
    $inparams.Properties_.Item('Type').Value=0x10200003
    $inparams.Properties_.Item('ID').Value='{9fc76b9c-f8ef-11e3-a7ec-7446a093755e}'
    $outParams=$store.ExecMethod_('CreateObject',$inparams)

    $inparams=$store.Methods_.Item('OpenObject').InParameters.SpawnInstance_()
    $inparams.Properties_.Item('ID').Value = '{9fc76b9c-f8ef-11e3-a7ec-7446a093755e}'
    $outParams=$store.ExecMethod_('OpenObject',$inparams)
    $objBootLoader = $outParams.Properties_.Item('Object').Value

#The codes list as below could not works, does anyone can help me to find a way to create device/osdevice element with powershell? Thanks in advance...

    $inparams=$objBootLoader.Methods_.Item('SetFileDeviceElement').InParameters.SpawnInstance_()
    $inparams.Properties_.Item('AdditionalOptions').Value = '{9fc76b9c-f8ef-11e3-a7ec-7446a093755c}'
    $inparams.Properties_.Item('DeviceType').Value = '4'
    $inparams.Properties_.Item('ParentDeviceType').Value = '2'
    $inparams.Properties_.Item('ParentPath').Value = '\\Device\\HarddiskVolume1'
    $inparams.Properties_.Item('Path').Value = '\\boot.wim'
    $inparams.Properties_.Item('Type').Value = 0x21000001
    $inparams.Properties_.Item('ParentAdditionalOptions').Value='""'
    $outParams=$objBootLoader.ExecMethod_('SetFileDeviceElement',$inparams)

}

I tried to create object with BcdDeviceData, but it not works.



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>