gpt4 book ai didi

PowerShell 映射持久共享点路径

转载 作者:行者123 更新时间:2023-12-04 01:28:51 25 4
gpt4 key购买 nike

我正在尝试以持久的方式将路径映射到 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com