Skip to content

Instantly share code, notes, and snippets.

@FilipChalupa
Last active April 8, 2020 09:02
Show Gist options
  • Save FilipChalupa/7c4dedec4541ee097f145f874361a297 to your computer and use it in GitHub Desktop.
Save FilipChalupa/7c4dedec4541ee097f145f874361a297 to your computer and use it in GitHub Desktop.
Write-Host "Synchronizing your docker time."
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if ($principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
$name = (Get-VMIntegrationService -VMName DockerDesktopVM | Where-Object { $_.Id.StartsWith("Microsoft:") -and $_.Id.EndsWith("\2497F4DE-E9FA-4204-80E4-4B75C46419C0") }).Name # "Time Synchronization" for English Windows
Get-VMIntegrationService -VMName DockerDesktopVM -Name $name | Disable-VMIntegrationService
Get-VMIntegrationService -VMName DockerDesktopVM -Name $name | Enable-VMIntegrationService
echo $name
Write-Host "Time synced!"
Read-Host -Prompt "Press Enter to exit."
} else {
Write-Host "Elevated privileges are required."
Start-Process -FilePath "powershell" -ArgumentList "$('-File ""')$(Get-Location)$('\')$($MyInvocation.MyCommand.Name)$('""')" -Verb runAs
}
@FilipChalupa
Copy link
Author

On my machine: Microsoft:E43C372E-23C2-41A6-89E7-5FBF3A080CAC\2497F4DE-E9FA-4204-80E4-4B75C46419C0

@FilipChalupa
Copy link
Author

Making the script respect locale seems doable.

@odalet
Copy link

odalet commented Apr 6, 2020

Yes, this seems to work:

$name = (Get-VMIntegrationService -VMName DockerDesktopVM | Where-Object { $_.Id.StartsWith("Microsoft:") -and $_.Id.EndsWith("\2497F4DE-E9FA-4204-80E4-4B75C46419C0") }).Name

@FilipChalupa
Copy link
Author

Nice. Good job. I've updated the original gist. Thank you. :)

@odalet
Copy link

odalet commented Apr 6, 2020

👍

@odalet
Copy link

odalet commented Apr 8, 2020

By the way, I upgraded my Docker for Windows to version 2.2.0.5 and it seems to be much better at resyncing time after the PC went to hibernation. Anyway the script may still prove useful if there are cases when sync fails!

@FilipChalupa
Copy link
Author

👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment