How does Window 10 hardcode the path to UEFI that should be used instead of GRUB?

I had an installation of Ubuntu since > 3 years working well in a dual-boot setting with Windows 10. 90% of the times I use Ubuntu only, but today I booted into Windows to play a game and it took me for a ride of about 3 hours updating the OS.

Post that update, I realised whenever system was booting, it was directly going to UEFI file located at /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi.

After spending some 8+ hours trying to bring GRUB back from the grip of Windows, I replaced the path

/boot/efi/EFI/Microsoft/Boot/bootmgfw.efi

with file from

/boot/efi/EFI/ubuntu/grubx64.ef

I did take proper backup. The above setting did work, and now Grub is back from almost dead.

I am very curious to know more about how this thing happens, and Windows acquires a lock on which file the firmware will look up to.

I had secure boot disabled since few years. I had tried tools like EasyUEFI and efibootmgr, but on every reboot, the control was going straight to Windows.

This may be naive question, but can anyone please shed light on how UEFI lock happens and what can we do to prevent this from happening?

P.S: As of now, I have disabled Windows Update services to get rid of this trouble.

How to hard-code O365 credentials in Powershell script

I am using the PowerShell script mentioned here: http://www.sharepointdiary.com/2016/11/sharepoint-online-import-terms-to-termset-using-powershell.html to update the term store values and its working perfectly.

However, I need to schedule this Powershell to run through task scheduler so that it can run every hour. For this reason, I want to hard-code credentials that connects to SPOnline. But for some reason I am seeing below error.

enter image description here

I tried to make below change in Powershell to hard-code credentials:

#Load SharePoint CSOM Assemblies Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"  #Variables for Processing  $  AdminURL = "https://abc-admin.sharepoint.com/" $  TermGroupName= "Site Collection - abc.sharepoint.com-sites-123site" $  TermSetName="Due Diligence" $  CSVFile ="C:\Users\dm123\Downloads\TermStore.csv" $  TermHeaderInCSV ="Due Diligence"  Try {     #Get Credentials to connect     $  Username = "123@abc.com"     $  Password ="LE$  b1yuio$  !."     $  Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($  Username, $  Password)      #Setup the context     $  Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($  AdminURL)     $  Ctx.Credentials = $  Credentials      #Get the term store     $  TaxonomySession=[Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($  Ctx)     $  TaxonomySession.UpdateCache()     $  TermStore =$  TaxonomySession.GetDefaultSiteCollectionTermStore()     $  Ctx.Load($  TaxonomySession)     $  Ctx.Load($  TermStore)     $  Ctx.ExecuteQuery()      #Get Termstore data from CSV and iterate through each row     Import-Csv $  CSVFile | ForEach-Object {          #Get the Term Group         $  TermGroup=$  TermStore.Groups.GetByName($  TermGroupName)          #Get the term set         $  TermSet = $  TermGroup.TermSets.GetByName($  TermSetName)          #CSV File Header Row in Term to Add         $  TermName = $  _.$  ($  TermHeaderInCSV)          #Check if the given term exists already         $  Terms = $  TermSet.Terms         $  Ctx.Load($  Terms)         $  Ctx.ExecuteQuery()         $  Term = $  Terms | Where-Object {$  _.Name -eq $  TermName}          If(-not $  Term)         {             #Create Term Set             Write-host "Creating Term '$  TermName'" -ForegroundColor Cyan             $  Term = $  TermSet.CreateTerm($  TermName,1033,[System.Guid]::NewGuid().toString())             $  Ctx.Load($  Term)             $  Ctx.ExecuteQuery()             $  Term.TermStore.CommitAll()             $  TaxonomySession.UpdateCache()             Write-host "New Term '$  TermName' Added Successfully!" -ForegroundColor Green         }         else         {             Write-host "Term '$  TermName' Exists Already!" -ForegroundColor Yellow         }     }  } Catch {     write-host -f Red "Error Importing Term store Data!" $  _.Exception.Message } 

Can someone please help me resolve the error, I simply need to hard-code the credentials. Thanks in advance.