我希望有人能夠闡明這一點,因爲它一直在讓我分心。無法打開共享點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正在等待 –