I use Vagrant to run a VM with Win Server 2019 utilizing Virtualbox with a synced folder called "sync".

  config.vm.define :winw1 do |winw1|
    winw1.vm.provider :virtualbox do |vb|
    winw1.vm.synced_folder "./win", "C:\\sync"

Once it is up, I open PowerShell to run a .ps1 script from this folder and get this error

powershell 'C:\sync\k.ps1'
powershell.exe : C:\sync\k.ps1 : The term 'C:\sync\k.ps1' is not recognized as the name of a cmdlet, function, 
    + CategoryInfo          : NotSpecified: (C:\sync\k.ps1 :...let, function, :String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:1 char:1+ C:\sync\k.ps1+ ~~~~~~~~~~~~~    + CategoryInfo          : ObjectNotFound: (C:\sync\k.ps1:String) [], CommandNotFoundException    + FullyQualifiedErrorId : CommandNotFoundException make: *** [Makefile:13: run] Error 1

if I move to the dir and try to list it's content I get

PS C:\Windows\system32> cd C:\
PS C:\> ls

    Directory: C:\

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        3/10/2021  12:10 AM                PerfLogs
d-r---        4/10/2021   5:46 AM                Program Files
d-----         3/9/2021  11:55 PM                Program Files (x86)
d----l        4/10/2021   5:44 AM                sync
d-r---         3/9/2021  11:52 PM                Users
d----l        4/10/2021   5:44 AM                vagrant
d-----        4/10/2021   5:43 AM                Windows

PS C:\> cd C:\sync
PS C:\sync> ls
ls : Could not find a part of the path 'C:\sync'.
At line:1 char:1
+ ls
+ ~~
    + CategoryInfo          : ReadError: (C:\sync:String) [Get-ChildItem], DirectoryNotFoundException
    + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

However, if I open the explorer and navigate to C:\sync and then run the same command again in PS the script just works. It does not help if I just wait or at least waiting 17 minutes did not help. Is there a way to refresh the file system via powershell commands, so I can automize this further?


You must log in to answer this question.

Browse other questions tagged .