My goal is to map a network drive in Windows to a WebDAV server via PowerShell.
I have a script that automatically creates an Azure VM with IIS installed and WebDAV configured. I can successfully map manually the network drive via Windows Explorer to the WebDAV server (using the option to use different credentials). That confirms that the WebDAV server is configured correctly. I can read and write files, too.
Via PowerShell I have tried to use the command New-PSDrive and get errors as you see.
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
OR without the parameter -Persist
New-PSDrive –Name $networkDrive –PSProvider FileSystem –Root "http://$serviceName.cloudapp.net/"
New-PSDrive : The specified drive root "http://webdavservertest3.cloudapp.net/" either does not exist, or it is not
a folder.
At line:1 char:1
+ New-PSDrive –Name $networkDrive –PSProvider FileSystem –Root "http:// ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ReadError: (Z:PSDriveInfo) [New-PSDrive], IOException
+ FullyQualifiedErrorId : DriveRootError,Microsoft.PowerShell.Commands.NewPSDriveCommand
As one can see the term "http://$serviceName.cloudapp.net/"
successfully evaluates to "http://webdavservertest3.cloudapp.net/"
.
So, is this the right approach? Should New-PSDrive be capable of mapping to WebDAV servers? If not, any idea to map the network drive via PowerShell?