How to change the position of search box in SharePoint Online?

Try running below PowerShell script:

$userName = ""
$passWord = "YourSPOPassword"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
Connect-PnPOnline -Url "" -Credentials $cred
#Example as below:
Connect-PnPOnline -Url "" -Credentials $cred
    $web = Get-PnPWeb
    #0 - Inherit, #1 - AllPages, #2 - ModernOnly, #3 - Hidden enums for Global (Modern Search)
    Write-Host "The changes have been updated successfully." -BackgroundColor Green
    $ErrorMessage = $_.Exception.Message +"in applying search setting changes!: "
    Write-Host $ErrorMessage -BackgroundColor Red
    Write-Log $ErrorMessage
Write-Host "The script execution has been completed successfully."

Source: Configure SharePoint search box in office 365 suite bar step by step