I'm trying to build a PS script for a SharePoint 2007 which will loop through a list of site collections and update files within the 'Style Library' folder.
foreach ($file in $files) {
$stream = $file.OpenRead()
$done = $list.RootFolder.SubFolders["FolderName"].Files.Add($file.Name, $stream, $true)
Write-Host $done.Name "Uploaded" -BackgroundColor Green
}
This loop tries to upload each file to the library but errors with the following message:
Exception calling "Add" with "3" argument(s): "The file "..." is not checked out. You must first check out this document before making changes."
I'm struggling to find a way to programmatically check out documents, upload the new copy and then check that in. Is there any way of working around this?
$file.CheckOut()