Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

powershell find specific word document in sharepoint libary

$
0
0

Hi all 

I am trying to find a word document which has some keywords in it.

But I can't get it right.

can someone please tell me what I am doing wrong? I am a novice at this.

Thanks

#Client modules laden (https://www.microsoft.com/en-us/download/details.aspx?id=42038)
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"  
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"   

if (Test-Path -path "C:\TEMP\encrypted.xml"){
#Username en password gehashed ophalen
$UserCred = Import-Clixml -Path "C:\TEMP\encrypted.xml"
$username = $UserCred.UserName
$password = $UserCred.Password
}Else{
#Maken gehashde xml (Per machine & User verschillend)
Get-Credential | Export-Clixml -Path C:\TEMP\encrypted.xml
}

#Site om verbinding mee te maken
$siteUrl = "https://mysite.sharepoint.com/sites/Test" 

#Verbind via de SP client context
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)  
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)  
$ctx.Credentials = $credentials 

$rootWeb = $ctx.Web  
$sites = $rootWeb.Webs
$ctx.Load($rootWeb) 
$ctx.Load($sites)
$ctx.ExecuteQuery()

#Sourcemap
$team = Read-Host -Prompt "Team (ICT, CT&M, F&V,D)"
$schooljaar = Read-Host -Prompt "Schooljaar (2019-2020,enz)"
$SourceFolder = "/Gedeelde  documenten/Taakgroep 07 Examenproducten en examenplannen/Vastgestelde examenproducten/$team/$schooljaar"

#Sourcefile
#Keywoorden waar op gezocht moet worden
Connect-PnPOnline -Url $siteurl -Credentials $UserCred
$crebo = Read-Host -Prompt "Crebocode" #'25189'
$cohort = Read-Host -Prompt "Cohort (2017,enz.)" #'2017'
$document = Read-Host -Prompt "Type document (examenplan, examenproduct)" #'examenplan'
$leerweg = Read-Host -Prompt "Leerweg (BOL, BBL)" #'BOL'

$SourceFile= Get-PnPFolderItem -FolderSiteRelativeUrl $SourceFolder -ItemType File | Where-Object {$_.Name -like '*.doc*'}

foreach ($SourceFile in $SourceFiles)
{
$path = $SourceFile.FullName
$Word = New-Object -ComObject Word.Application
$Word.Visible = $False
#$Document = $Word.Documents.Open($path) 
$Word.Visible = $False 
$Document.Paragraphs |where { $_ | 
Select-String -pattern ('$crebo') -SimpleMatch} | 
Select-String -pattern ('$cohort') -SimpleMatch |
Select-String -pattern ('$document') -SimpleMatch 

}
Write-Host("$crebo,$cohort,$document,$SourceFile")


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>