使用 Win Server 2019 刷新虚拟机的同步文件夹

使用 Win Server 2019 刷新虚拟机的同步文件夹

我使用名为“sync”的同步文件夹Vagrant来运行虚拟机。Win Server 2019Virtualbox

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

启动后,我打开 PowerShell 来从此文件夹运行 .ps1 脚本,然后收到此错误

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

如果我移动到目录并尝试列出它的内容我得到

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

但是,如果我打开资源管理器并导航到C:\syncPS 中,然后再次运行相同的命令,脚本就会正常工作。如果我只是等待,或者至少等待 17 分钟也没有帮助,这没有帮助。有没有办法通过 powershell 命令刷新文件系统,以便我可以进一步自动化?

相关内容