Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
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
)

# Create context and test the connection
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object System.Net.NetworkCredential($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 ="<View Scope='RecursiveAll' />";
$itemki=$ll.GetItems($spqQuery)
$ctx.Load($itemki)
$ctx.ExecuteQuery()

foreach($item in $itemki)
{

Write-Host $item["FileRef"] $item.ElementType

$file =
$ctx.Web.GetFileByServerRelativeUrl($item["FileRef"]);
$ctx.Load($file)
$ctx.Load($file.Versions)

$ctx.Load($file.ListItemAllFields)
$Author=$file.Author
$CheckedOutByUser=$file.CheckedOutByUser
$LockedByUser=$file.LockedByUser
$ModifiedBy=$file.ModifiedBy
$ctx.Load($Author)
$ctx.Load($CheckedOutByUser)
$ctx.Load($LockedByUser)
$ctx.Load($ModifiedBy)
$ctx.Load($file.EffectiveInformationRightsManagementSettings)
$ctx.Load($file.Properties)
try
{
$ctx.ExecuteQuery()
}
catch
{}

if($CheckedOutByUser.LoginName -ne $null){
Write-Host $file.Name
Write-Host $CheckedOutByUser.LoginName
$file.CheckIn('Checked in automatically', 'MajorCheckIn')
$ctx.Load($file)
try
{
$ctx.ExecuteQuery()
Write-Host $file.Name " has been checked in" -ForegroundColor DarkGreen
}
catch [Net.WebException]
{
Write-Host $_.Exception.ToString()
}

}



}
}









#Paths to SDK
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"

#Enter the data
$AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString
$username="AwesomeMachine\administrator"
$Url="http://ThisIsSharePoint/sites/site1"
$ListTitle="Documents"



Get-sPOFolderFiles -Username $username -Url $Url -password $AdminPassword -ListTitle $ListTitle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
The script requires SharePoint Online SDK.



What does it do?

The script finds all the checked out files in a single library and checks them in.



How to use?

1. Download and open the file.

2. Refer the paths to the SDK:



PowerShell
#Paths to SDK
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"


3. Enter your credentials, the url of the site and the name of the list

PowerShell
#Enter the data
$AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString
$username="AwesomeMachine\administrator"
$Url="http://ThisIsSharePoint/sites/site1"
$ListTitle="Documents"

4. Save the file, close, and run the script in Powershell.



The files will have the following check-in in their version history:



If you want to change the comment's content, modify the following line in the script:

PowerShell
$file.CheckIn('Checked in automatically', 'MajorCheckIn')