我的目标是通过 PowerShell 将 Windows 中的网络驱动器映射到 WebDAV 服务器。
我有一个脚本可以自动创建一个安装了 IIS 并配置了 WebDAV 的 Azure VM。我可以通过 Windows 资源管理器成功地将网络驱动器手动映射到 WebDAV 服务器(使用使用不同凭据的选项)。这确认 WebDAV 服务器配置正确。我也可以读写文件。
通过 PowerShell,我尝试使用命令 New-PSDrive 并得到如您所见的错误。
New-PSDrive –Name $networkDrive –PSProvider FileSystem –Root "http://$serviceName.cloudapp.net/" –Persist
New-PSDrive : When you use the Persist parameter, the root must be a file system location on a remote computer.
At line:1 char:1
+ New-PSDrive –Name $networkDrive –PSProvider FileSystem –Root "http:// ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Z:PSDriveInfo) [New-PSDrive], NotSupportedException
+ FullyQualifiedErrorId : DriveRootNotNetworkPath,Microsoft.PowerShell.Commands.NewPSDriveCommand
Run Code Online (Sandbox Code Playgroud)
或不带参数 -Persist
New-PSDrive …
Run Code Online (Sandbox Code Playgroud)