Hi, I would like to get some help with creating a script. The powershell script needs to have the ability to sign in to sharepoint, have input prompts for site, site pages and library to copy from and to. I need to be able to copy to a different library in another site and on top of that filter the files by creator. (maybe the creators email address??)
I am a newbie I admit, I have searched and search for a script that does this and I have tried to get something that works but to no avail as yet as now I have a knowledge block!
I would be grateful for the help and some knowledge insight.
Many thanks
Nigel
This is what I have so far:-
Do{
# Source document library full path
$FullSiteUrl = "https://oursite"
$SourceURL = Read-Host "Enter the source Url - (EXAMPLE: sites/template/icon)"
$TargetURL = Read-Host "Enter the Target Url - (EXAMPLE: sites/365training)"
$libraryName = Read-Host "Enter the name the Library i.e. 'sitePages'"
$AuthorEmail = Read-Host "Enter the name of the Author of the files that you want to copy to the destination site"
Write-Host "The entered Source Tenant URL is" $FullSiteUrl -ForegroundColor Green
Write-Host "The entered Source url is" $SourceURL -ForegroundColor Green
Write-Host "The entered Target URL is" $TargetURL -ForegroundColor Green
Write-Host "The entered Library Name is" $libraryName -ForegroundColor Green
Write-Host "The entered Author is" $AuthorEmail -ForegroundColor Green
$Confirmation = Read-Host -Prompt "Is this correct? (y/n)"
}
while ($Confirmation -ne "y")
#Connect To Site
Write-Host "Connecting to site" -ForegroundColor Yellow
Connect-PnPOnline -url $FullSiteUrl -Interactive
Write-Host "Connected" -ForegroundColor Green
Get-PnPListItem -List $libraryName | where {$_.FieldValues.Author.Email -eq $AuthorEmail -and $_.FileSystemObjectType -eq "File"}
$sourceFieldCol = $sourceList.FieldsValues;
$sourceItems = $sourceList
$var1 = $item.FieldValues.FileLeafRef
$destinationList = Get-PnPListItem -List $libraryName
#Copy data$($item.FieldValues.FileLeafRef)
#Copy-PnPFile -SourceUrl $SourceURL/$LibraryName -TargetUrl $TargetURL/$LibraryName