PowerShell 映射持久共享点路径

标签 powershell sharepoint mapping

我正在尝试以持久的方式将路径映射到 SharePoint 文档库。奇怪的是,这工作正常:

$Sharepoint = '\\domain.net\stuff\Documents\Folders - Permission matrix'
New-PSDrive -Name P -Root $Sharepoint -PSProvider FileSystem -Credential $Credentials

但这行不通:

New-PSDrive -Persist -Name P -Root $Sharepoint -PSProvider FileSystem -Credential $Credentials
New-PSDrive : The network resource type is not correct
At line:1 char:1
+ New-PSDrive -Persist -Name P -Root $Sharepoint -PSProvider FileSystem -Credentia ...

这些命令都使用相同的 PSProvider,但一个是持久的,另一个不是。如何在不恢复为 net use 的情况下保持这种持久性?

最佳答案

几周前我在一个脚本中遇到了这个问题,在我开发它时神秘地停止工作,似乎是 Windows 错误 66 而不是 Powershell as explained here

这是使用凭据的 net use 的替代方法

# map drive using credentials
(New-Object -ComObject WScript.Network).MapNetworkDrive("$LocalDrive","\\$computer\$drive",$false,$($credentials.username),$($credentials.GetNetworkCredential().password))

我倾向于这样使用 PSDrive

    # discover and delete
    if (Get-PSDrive -Name Results -ErrorAction SilentlyContinue) { Remove-PSDrive -Name Results -Scope Global | Out-Null }

    # create using credentials
    if ((New-PSDrive -Name Results -PSProvider FileSystem -Root "\\server\share" -Credential $Credentials -Scope Global -ErrorAction SilentlyContinue) -eq $null)  { $WSHShell.popup(“You do not have access to the results repository“,0,””,0) | Out-Null }

    # call from a separate function
    (Get-PSDrive -Name Results).root

可能只是重启会解决问题,因为我今天无法重现该问题。

关于PowerShell 映射持久共享点路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30298850/

相关文章:

powershell - 将列表中的行添加到第二个列表Powershell中的行

默认情况下,ElasticSearch 5.1 Fielddata 在文本字段中被禁用 [ERROR : trying to use aggregation on field]

string - 将矩阵元素映射到字符串

javascript - .map() 将数组放入 renderRow() 内的 JSX 中

c# - 绑定(bind)一个下拉列表,然后添加一个新的列表项

powershell - PowerTools 更新-TfsWorkspace 未获取最新版本

powershell - 使用 PowerShell 下载文件

sql-server - 如果尚未安装,仅安装 PowerShell PackageProvider 和 Module

sharepoint - 如何使用 graph api beta 从 sharepoint 站点获取列表

java - 使用 java 在 Sharepoint 中读取 Excel 文件