0

When trying to open or sometimes close, via powershell, a word document in a sharepoint directory hosted in my company's network, the windows security box popup. How can I authenticate this ? Here is part of my script:

$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()

Here is a visual example of what happens.

1 Answers1

0

I´ve found something that works, but only if if have an admin user. Still would like to know if there is a way to do this without this kind of permission. Here is the code:

$User = "domain\useradmin"
$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 

 }