我希望有人能够阐明这一点,因为它一直在让我分心。无法打开共享点UNC路径,除非已通过Windows资源管理器打开
我有一个脚本,它将通过UNC路径将其创建的报告保存到SharePoint文档库中(如果路径存在),否则将作为回退保存到网络驱动器位置的UNC路径。
我注意到,与test-path
检查,保存(通过msexcel的COM对象),或者尝试使用invoke-item
如果我已经访问SharePoint网站只工作(通过Web浏览器或窗口打开Windows资源管理器的文件夹资源管理器),因为电脑上次登录(我正在运行Windows 7企业服务包1 - 64位版本)。
如果自上次登录后我还没有手动分享点,则test-path
返回false,其他方法会导致ItemNotFoundException
例如,的代码
ii : Cannot find path '\\uk.sharepoint.mydomain.local\sites\mycompany\myteam\Shared Documents\Reports' because it does not exist.
At line:1 char:1
+ ii '\\uk.sharepoint.mydomain.local\sites\mycompany\myteam\Shared Document ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (\\uk.sharepoint...\Reports:String) [Invoke-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.InvokeItemCommand
例领域:
$workbook._SaveAs($fileout,[Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook,$Missing,$Missing,$false,$false,[Microsoft.Office.Interop.Excel.XlSaveAsAccessMode]::xlNoChange,[Microsoft.Office.Interop.Excel.XlSaveConflictResolution]::xlLocalSessionChanges,$true,$Missing,$Missing)
:
$LANPath = "\\myserver\myshare\teamdirs\scriptdir"
$SharepointPath = "\\uk.sharepoint.mydomain.local\sites\mycompany\myteam\Shared Documents\Reoprts"
$ScriptPath = $LANPath + "\bin"
If (Test-Path $SharepointPath) {$BasePath = $SharepointPath;write-host "Using sharepoint to save reports"} else {$BasePath = "$LANPath\Reports";write-host "Using LAN to save reports - sharepoint not accessible"}
和
$_|select -expandproperty HTMLBody | Out-File $($BasePath + "\Eml_body.html")
Write-Host "Reformating HTML"
$html = New-Object -ComObject "HTMLFile";
$source = Get-Content -Path ($BasePath + "\Eml_body.html") -Raw;
和从我的COM对象内保存Excel电子表格时
我有一种感觉,WebClient服务将能够帮助你。'$ webclient = New-Object System.Net.WebClient'这是Windows资源管理器用来访问SharePoint位置的服务。作为参考:https://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.110).aspx – Thriggle
@Thriggle啊,当然,这是一个运行WebDAV的Web服务器,而不是文件服务器。像鸭子一样走路,鸭子像鸭子......不是鸭子!我有一个使用webclient的游戏,但在将UseDefaultCredentials设置为true时无法进行身份验证。相反,我已经使用了Invoke-WebRequest,因为它应该足以让站点进入WebDAV缓存,此后UNC路径应该可以工作。如果你张贴作为答案,我会相应地标记为答案。我使用的语法是“Invoke-WebRequest -Uri”http://uk.sharepoint.mydomain.local/sites/mycompany/myteame/Shared Documents/Reports“-UseDefaultCredentials' –
Scratch that - ”Invoke-WebRequest' for the access但是因为它没有使用UNC路径,所以我不需要调用WebDAV,所以我需要重新访问WebClient并了解为什么'UseDefaultCredentials'导致认证错误 - 更多的搜索和搜索SO正在等待 –