<# .SYNOPSIS Checks out files in a SharePoint document library. .DESCRIPTION The script checks out a single file or loops through a document library and checks out all files. .PARAMETER url subsite url. .PARAMETER folder folder name .PARAMETER file file name .PARAMETER checkOutType checkout type Online or Offline .PARAMETER all checks out all files. .EXAMPLE PS > .\CheckOut-SPFile.ps1 -url http://nimaintra.net -folder "Shared Documents" ` >> -CheckoutType Online -all Checks out all files that are not already checked out in the "Shared Documents" document library #> param( [string]$url, [string]$folder, [string]$file, [string]$checkOutType, [switch]$all ) $spAssignment = Start-SPAssignment $spWeb = Get-SPWeb $url -AssignmentCollection $spAssignment # Check if All files should be checked out if($all) { # Get the folder $spFolder = $spWeb.GetFolder($folder) # Store file collection in a variable $spFileCollection = $spFolder.Files # loop through files and check out if # file is not already checked out $spFileCollection | ForEach-Object { # check if file is not checked out if($_.CheckOutType -eq "None") { # check out file $_.CheckOut($checkOutType,$null) Write-Host $_.Name checked out } else { Write-Host $_.Name already checked out } } } else { # store file URL in a variable $fileURL = $folder + "/" + $file $spFile = $spWeb.GetFile($fileURL) # check if file is not checked out if($spFile.CheckOutType -eq "None") { # check out file $spFile.CheckOut($checkOutType,$null) Write-Host $spFile.Name checked out } else { Write-Host $spFile.Name already checked out } } Stop-SPAssignment $spAssignment