当试图通过powershell打开或有时关闭我公司网络中托管的sharepoint目录中的word文档时,windows安全框弹出。我如何对此进行身份验证?这是我的部分脚本:
$docpath = "\sharepoint.[Domain].com[...]mydoc.docx"
$word = New-Object -ComObject Word.Application
$word.Visible = $true
$doc = $word.Documents.Open("$docpath")
{...process...}
$doc.Close([ref]$true)
$word.Quit()
$word = $null
[gc]::collect()
[gc]::WaitForPendingFinalizers()
下面是一个直观的例子。
我发现了一些有效的东西,但前提是有管理员用户。仍然想知道是否有办法在没有这种许可的情况下做到这一点。这是代码:
$User = "domainuseradmin"
$Cred = Get-Credential -Credential $User
$srv = "sharepoint.[Domain].com"
Invoke-Command -ComputerName $srv -Credential $Cred -ScriptBlock{
$docpath = "\sharepoint.[Domain].com[...]mydoc.docx"
$word = New-Object -ComObject Word.Application
$word.Visible = $true
$doc = $word.Documents.Open("$docpath")
{...process...}
$doc.Close([ref]$true)
$word.Quit()
$word = $null
}