我的漫游配置文件 powershell 生成问题 - 尝试对“FileSystem”提供程序执行 InitializeDefaultDrives 操作失败

我的漫游配置文件 powershell 生成问题 - 尝试对“FileSystem”提供程序执行 InitializeDefaultDrives 操作失败

这真是一个令人讨厌的错误 -尝试对“FileSystem”提供程序执行 InitializeDefaultDrives 操作失败。,每次我在公司网络外部启动 powershell 时都会得到这个信息。

屏幕截图

错误

简短描述:

我在域中有一个笔记本。我使用它的方式有两种。第一种是在公司网络内,一切正常。第二种方式是在办公室外通过 VPN 连接。每次启动 powershell 时都会出现上述错误。

搜索驱动器的脚本:

根据我对错误的搜索,原因似乎是无法连接的驱动器或资源。

我尝试找出可能的原因。由于主文件夹结构发生了一些变化,我怀疑是它造成的。

我已经在两个位置执行了此脚本:

Write-Verbose -Message 'Get-PSDrive -PSProvider FileSystem' -verbose
echo 'Get-PSDrive -PSProvider FileSystem' | Out-File -Append -Encoding "UTF8" -FilePath filesystem.log
Get-PSDrive -PSProvider FileSystem | Out-File -Append -Encoding "UTF8" -FilePath filesystem.log

Write-Verbose -Message 'net use' -verbose 
echo 'net use' | Out-File -Append -Encoding "UTF8" -FilePath filesystem.log
net use | Out-File -Append -Encoding "UTF8" -FilePath filesystem.log

Write-Verbose -Message '[System.IO.DriveInfo]::GetDrives() | Format-Table' -verbose
echo '[System.IO.DriveInfo]::GetDrives() | Format-Table' | Out-File -Append -Encoding "UTF8" -FilePath filesystem.log

[System.IO.DriveInfo]::GetDrives() | Format-Table | Out-File -Append -Encoding "UTF8" -FilePath filesystem.log

# does not work properly
# Write-Verbose -Message 'Get-CimInstance -ClassName Win32_LogicalDisk -ComputerName $env:COMPUTERNAME' -verbose | Out-File -Append -Encoding "UTF8" -FilePath filesystem.log
#Get-CimInstance -Class Win32_LogicalDisk | Out-File -Append -Encoding "UTF8" -FilePath filesystem.log

Write-Verbose -Message 'Get-CimInstance -Class Win32_NetworkConnection' -verbose 
echo 'Get-CimInstance -Class Win32_NetworkConnection' | Out-File -Append -Encoding "UTF8" -FilePath filesystem.log
Get-CimInstance -Class Win32_NetworkConnection | Out-File -Append -Encoding "UTF8" -FilePath filesystem.log

结果:

似乎有 U:\ 潜伏在阴影中(在现场时不会出现)。这是已断开连接且不应再使用的网络驱动器。(有一些旧程序正在使用它,应通过 GPO 规则应用它)

net use生成:

U:        \\server_name\U_login_name$   NFS Network

[System.IO.DriveInfo]::GetDrives() | Format-Table生成:

Name            DriveType DriveFormat       IsReady AvailableFre TotalFreeSpa   TotalSize RootDirecto VolumeLabel
                                                          eSpace           ce             ry                     
----            --------- -----------       ------- ------------ ------------   --------- ----------- -----------
C:\                 Fixed NTFS                 True   1779298304   1779298304 ...43488000 C:\         OSDisk     
U:\               Network                     False                                       U:\  

Get-CimInstance -Class Win32_NetworkConnection

LocalName                    RemoteName                   ConnectionState             Status                     
---------                    ----------                   ---------------             ------                     

U:                           \\server_name\U_login_name$      Disconnected                Unavailable                

另一方面,当直接在公司网络上时,根本就没有 U:\ 之类的东西。

我尝试过哪些方法来纠正这种情况

  • 手动断开

    1)通常情况下(右键单击断开连接)会产生错误此网络连接不存在

    2)使用 NFS 时umount u:

    Disconnecting           U:      \\server_name\U_login$
    There are open files and/or incomplete directory searches pending on the connection.
    
    Do you want to continue this operation? (Y/N) [N]:y
    
    Network Error - 2250    Not Connected
    

    3)尝试强制断开所有 NFS 挂载(U:驱动器被报告为 NFS 共享)umount -f -a

    Network Error - 2250    Not Connected
    
  • 在网上找到的建议:

    1)更改 GPO

    要解决此问题,请通过组策略应用以下设置:

    User Configuration/Administrative Templates/System/Scripts/Run logon scripts synchronously = Enabled

(注意:使用漫游配置文件时,计算机启动速度非常非常慢。必须禁用此设置)

2)映射驱动器不会消失

我对这个链接寄予厚望映射驱动器不会消失 - 登录时不断重新连接 我和帖子中的感受一样——引用:

>  I have indeed checked scripts and GPOs and this is nowhere to be found there. This looks more like a manual mapping that had the
> "Reconnect on logon" checkbox checked and is now so persistent that
> there was no "normal" way to undo it.

不幸的是,那里的每一个建议都失败了。

  • 注册表

    1)我在注册表中搜索了该字符串,并在这里找到了它:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2]。我尝试删除 U:驱动器密钥,但它不断出现。

2)我也在这里发现了它(但还没有尝试过;我不想破坏操作系统):

    Windows Registry Editor Version 5.00

    [HKEY_USERS\S-1-5-21-119559289-1840127793-336618761-855951\Volatile Environment]
    "HOMEDRIVE"="U:"
    "LOGONSERVER"="\\\\logon_server"
    "USERDNSDOMAIN"="dns_domain"
    "USERDOMAIN"="user_domain"
    "USERNAME"="login"
    "USERPROFILE"="C:\\Users\\login"
    "HOMEPATH"="\\"
    "HOMESHARE"="\\\\server_name\\U_login$"
    "APPDATA"="C:\\Users\\login\\AppData\\Roaming"
    "LOCALAPPDATA"="C:\\Users\\login\\AppData\\Local"
    "USERDOMAIN_ROAMINGPROFILE"="user_domain"

    [HKEY_USERS\S-1-5-21-119559289-1840127793-336618761-855951\Volatile Environment\1]
    "SESSIONNAME"="Console"
    "CLIENTNAME"=""

现在我得出结论,我的漫游配置文件有问题。我还需要找到漫游配置文件未使用正确信息进行更新的原因。

有谁知道如何/有经验解决此类问题吗?

答案1

最后,希望知道原因,并测试了一些场景。

首先,我要声明一下,这是一个 Windows NFS漏洞

作为一个普通人,我不知道该如何向微软报告此事。我会在这里和我的博客上报告此事。

状况要满足此错误传播的条件:

1)计算机必须在域中

2)你必须在内部网络和功能齐全的 VPN 上使用该计算机,并且必须在同一个配置文件上

3) 您必须安装 Microsoft 的 NFS 实现(别名 NFS 客户端)

4) 您必须让服务在计算机启动时自动启动。如果服务在启动时启动manual,并且在启动顺序完成后启动,则漏洞不会显现出来。

5)你必须有某种NFS 共享。这里的问题是 NFS 共享占用优先权而不是普通net use共享。如果您断开 NFS 共享,然后使用 映射它net use ... /persistent:yes,则此共享将在重新启动后被覆盖。重新启动后,它将被识别为NFS 共享再次产生错误。

如何处理?

简而言之: 设置Windows 服务的 NFS 客户端手动的自动的模式。使用任务计划程序或 gpedit 与我的 powershell 脚本结合使用安装卸载 NFS 共享。 不要停止Windows 服务的 NFS 客户端当一些股份被挂载时!

较长的答案:

使用我的脚本时请阅读以下信息:

注意事项和最佳实践(阅读很重要!):

A) NFS mount, at least the Microsoft's implementation, is NOT persistent over boots.  To overcome 
  this you have these options:                                                                    
  I) Schedule this script in Task scheduler under "ordinary" user e.g. DOMAIN\user and have the   
     check-box "Run with highest privileges" (in order to start the NFS Client service if stopped)
 II) Run it in the "Local Group Policy Editor" (gpedit.msc) under "Windows Settings\Scripts"      
     (Startup -> mount and Shutdown -> unmount) in the sections "Computer Configuration" (for all 
      users) or under "User configuration" (for one specific user)                                

B) Do !!!NOT!!! mount NFS drive on system-wide account as "nt authority\system".  At the first    
   glance this seems to be a good idea.  Don't be fooled, it is not!  When you mount NFS share    
   under "SYSTEM" account it will appear as fixed drive for all other users!  On "SYSTEM" account 
   it still will show as network share.  If you stop the NFS Client for Windows service, NOT      
   recommended when any NFS share active, and then start it again, then even under "SYSTEM"       
   account it will appear as "fixed" drive.  It will leave user no option other than restart for  
   unmount.                                                                                       

C) It is NOT a good idea to stop Client for NFS Service when you have NFS mounted.  It can lead   
   to unexpected states like the NFS share actually becoming a hard-drive for windows till reboot.

D) If the Client for NFS Service is started already then it is better not to stop it manually as  
   it can, under certain circumstances, refuse to start.  It is better to have a log-off script   
   take care of the unmount && stopping the service                                               

错误或服务器配置说明:

A) You are getting a powershell error:                                                            
   "Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider      
   failed."                                                                                       
   This error can be caused the NFS Client for Windows when service is starting with start of the 
   Windows.  It takes precedence over "ordinary" `net use` and it causes powershell to check      
   "FileSystem".                                                                                  

广告 A) 解决方案:使用此脚本挂载 NFS 共享 - 在启动时使用 gpedit 策略进行设置或者
您可以通过任务计划程序运行(它会尝试启动 NFS 客户端服务) - 该脚本必须具有这样做的权限不要忘记将服务“NFS 客户端”(“NfsClnt”)设置
为手动启动,这样它就不会随 Windows 启动而启动。

B) If you are getting this error message (at your NFS server):                                    
   "(rpc.mountd[7243]: refused mount request from 192.168.XX.XX for <mount>: illegal port 24784"  
      you are most probably trying to connect on port over 1024.  To connect to NFS share you need
      to have 'insecure' option at your /etc/exports (if missing fix it and run `exportfs -r`)    

提示:如果服务尚未启动,安装脚本需要 UAC 来启动服务。您可以:

1) run it manually - you will see UAC window                                                      
2) create a new Task in Task Scheduler and check the check box "Run it with highest privileges"   
3) create a startup powershell script in the local policies

NFS 或 Windows 共享网络驱动器(例如使用离线 Windows 功能)到云端

删除网络驱动器(在我的情况下是U:驱动器)

当您打开离线文件功能并将文件备份到网络驱动器时,可能会出现此问题。如果您的公司更改此设置以支持某些云服务,则当某些应用程序仍需要以前的网络驱动器,但您仍需要切换到新的云提供商时,这可能会给您的配置文件带来死锁情况。

如果您使用的NFS Client for windows是 Microsoft 的产品,可以按照以下方法删除以前的网络驱动器:

通过以下步骤摆脱了U:驱动器(尚未摆脱消息):

1)前往 ->Start Menu\Programs\Administrative Tools\Services for Network File System (NFS)

2)client for NFS右键单击项目并选择stop service

3)简单的手动删除即可奏效!!!!

net use u: /delete
--> U: was deleted successfully.

要让 Windows 忘记以前的驱动器并正确地将易失性环境设置为新配置,您必须重启

摆脱错误消息:尝试在“FileSystem”提供程序上执行 InitializeDefaultDrives 操作失败。

错误信息确实不是出现已Client for NFS停止状态。只需将其置于状态manual并通过脚本启动它即可。

相关内容