diff --git a/File Management/Restore previous versions in selected files the entire library/caml.ps1 b/File Management/Restore previous versions in selected files the entire library/RestorePreviousVersionsInSelectedFiles.ps1 similarity index 100% rename from File Management/Restore previous versions in selected files the entire library/caml.ps1 rename to File Management/Restore previous versions in selected files the entire library/RestorePreviousVersionsInSelectedFiles.ps1 diff --git a/Permissions/C#/Break Inheritance for all items in site/description.md b/Permissions/C#/Break Inheritance for all items in site/description.md new file mode 100644 index 00000000..e69de29b diff --git a/Permissions/C#/Delete all unique permissions in site/description.md b/Permissions/C#/Delete all unique permissions in site/description.md new file mode 100644 index 00000000..e69de29b diff --git a/Permissions/C#/Get Items with Unique Permissions in site collection/description.md b/Permissions/C#/Get Items with Unique Permissions in site collection/description.md new file mode 100644 index 00000000..e69de29b diff --git a/Permissions/C#/Get Lists with Unique Permissions/description.md b/Permissions/C#/Get Lists with Unique Permissions/description.md new file mode 100644 index 00000000..e69de29b diff --git a/Versioning/PS Restore previous versions in selected files the entire library/RestorePreviousVersionsInSelectedFiles.ps1 b/Versioning/PS Restore previous versions in selected files the entire library/RestorePreviousVersionsInSelectedFiles.ps1 new file mode 100644 index 00000000..67a8430b --- /dev/null +++ b/Versioning/PS Restore previous versions in selected files the entire library/RestorePreviousVersionsInSelectedFiles.ps1 @@ -0,0 +1,116 @@ +function Get-SPOFolderFiles +{ +param ( + [Parameter(Mandatory=$true,Position=1)] + [string]$Username, + [Parameter(Mandatory=$true,Position=2)] + [string]$Url, + [Parameter(Mandatory=$true,Position=3)] + $password, + [Parameter(Mandatory=$true,Position=4)] + [string]$ListTitle + ) + + + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $ctx.Load($ctx.Web) + $ctx.ExecuteQuery() + $ll=$ctx.Web.Lists.GetByTitle($ListTitle) + $ctx.Load($ll) + $ctx.ExecuteQuery() + $spqQuery = New-Object Microsoft.SharePoint.Client.CamlQuery + $spqQuery.ViewXml ="/VersionTest/Folder2/FolderWithinFolder"; + $itemki=$ll.GetItems($spqQuery) + $ctx.Load($itemki) + $ctx.ExecuteQuery() + + foreach($item in $itemki) + { + + + # Write-Host $item["FileRef"] -ForegroundColor DarkGreen + $file = + $ctx.Web.GetFileByServerRelativeUrl($item["FileRef"]); + $ctx.Load($file) + $ctx.Load($file.Versions) + try{ + $ctx.ExecuteQuery() } + catch + { + continue; + } + + #$file.TimeLastModified + $date=Get-Date ("2/12/2017") + + if($file.TimeLastModified -gt $date) + { + + Write-host $file.Name -ForegroundColor Green + if ($file.Versions.Count -eq 0) + { + $obj=New-Object PSObject + $obj | Add-Member NoteProperty ServerRelativeUrl($file.ServerRelativeUrl) + $obj | Add-Member NoteProperty FileLeafRef($item["FileLeafRef"]) + $obj | Add-Member NoteProperty Versions("No Versions Available") + + #$obj | export-csv -Path $CSVPath -Append + + Write-Output $obj + } + elseif($file.TypedObject.ToString() -eq "Microsoft.SharePoint.Client.File") + { + + foreach ($vv in $file.Versions){ + Write-Host $vv.Created $vv.Size $vv.VersionLabel $vv.IsCurrentVersion $file.Versions.Count + + # Write-Output $vv + + } + if($file.Versions[($file.Versions.Count-1)].IsCurrentVersion) + { + $vLabel=$file.Versions[($file.Versions.Count-2)].VersionLabel + Write-Host "Version to be restored: " $vLabel + } + else{ $vLabel=$file.Versions[($file.Versions.Count-1)].VersionLabel + Write-Host "Version to be restored: " $vLabel } + $file.Versions.RestoreByLabel($vLabel) + $ctx.ExecuteQuery() + } + + else + { +$obj = New-Object PSObject +$obj| Add-Member NoteProperty FileLeafRef($item["FileLeafRef"]) + $obj | Add-Member NoteProperty Versions("No Versions Available") + Write-Output $obj + } + + + } + + + } + + + + + + + +} + +#Paths to SDK +Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" +Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" + +#Enter the data +$AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString +$username="t@testova365.onmicrosoft.com" +$Url="https://testova365.sharepoint.com/sites/STS" +$ListTitle="VersionTest" + + + +Get-sPOFolderFiles -Username $username -Url $Url -password $AdminPassword -ListTitle $ListTitle \ No newline at end of file diff --git a/Versioning/PS Restore previous versions in selected files the entire library/description.md b/Versioning/PS Restore previous versions in selected files the entire library/description.md new file mode 100644 index 00000000..b3d3567b --- /dev/null +++ b/Versioning/PS Restore previous versions in selected files the entire library/description.md @@ -0,0 +1,55 @@ +The script retrieves all files and restores the LAST NOT CURRENT version of the file. + +Please test the script in test environment before using it in production. + + + +The script is a modification of the existing Restore Previous Versions script created to show 2 ways on filtering the file results. The filters are only examples that need to be adjusted to your specific needs. + +The first filter uses CamlQuery to retrieve only files coming from a specific folder. + +The second filter takes files we have already retrieved and selects only those modified after 12/2/2017. + +When dealing with large number of files CamlQuery is the preferred and more efficient way. + + + + + + The script requires SharePoint Online SDK. Make sure that the paths below point to locations on your computer: + + + +PowerShell +#Paths to SDK +Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" +Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" + + + + + + + +The script needs to be edited before running. Enter the necessary data: + + + +```PowerShell +#Enter the data +$AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString +$username="t@testova365.onmicrosoft.com" +$Url="https://testova365.sharepoint.com/sites/STS" +$ListTitle="VersionTest" +``` +The CamlQuery below chooses only files whose ServerRelativeUrl includes a certain path. In this way you can restore versions only from a specific folder. +PowerShell + $spqQuery.ViewXml ="/VersionTest/Folder2/FolderWithinFolder"; + + The following lines allow us to narrow the files only to those modified after 12/2/2017. +PowerShell + $date=Get-Date ("2/12/2017") + + if($file.TimeLastModified -gt $date) + { +