A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
The script you shared can run normally in my environment.
The way to solve "The term ‘Get-SPWeb’ is not recognized as the name of a cmdlet, function" PowerShell error is to add
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
More reference:
https://global-sharepoint.com/powershell/how-to-fix-the-the-term-get-spweb-is-not-recognized-as-the-name-of-a-cmdlet-function-powershell-error/
If you are using SharePoint Online,you could referto this blog:
https://social.technet.microsoft.com/wiki/contents/articles/34215.sharepoint-online-get-all-checked-out-files-using-powershell.aspx
Updated------------------------------
$username = "******@contoso.onmicrosoft.com"
$password = "Password"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)
Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/dev -Credentials $cred
$list=Get-PnPList "lib"
$allDocs = (Get-PnPListItem -List $list)
foreach ($doc in $allDocs) {
if ($null -ne $doc.FieldValues.CheckoutUser.LookupValue) {
write-host $doc.FieldValues.FileRef
Set-PnPFileCheckedIn -Url $doc.FieldValues.FileRef
}
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.