I tried to run a script from Bulk delete files from library using name of file
$webUrl = ''
$listName = ''
$query = '<Where>' +
'<Contains>' +
'<FieldRef Name="FileLeafRef"/><Value Type="Text">bad_file</Value>' +
'</Contains>' +
'</Where>'
$viewFields = '<FieldRef Name="FileRef"/><FieldRef Name="FileLeafRef"/>'
$delete = $false
Start-SPAssignment -Global
try {
$web = Get-SPWeb $webUrl
$list = $web.Lists[$listName]
$spQuery = New-Object -TypeName Microsoft.SharePoint.SPQuery
$spQuery.Query = $query
$spQuery.ViewFields = $viewFields
$spQuery.ViewFieldsOnly = $true
$spQuery.ViewAttributes = 'Scope="Recursive"'
$items = $list.GetItems($spQuery)
$items | Select-Object ID, @{Name="FileName";Expression={$_["FileLeafRef"]}} |
Export-Csv -Path ".\FilesToDelete.csv" -NoTypeInformation
if ($delete) {
$batch = '<?xml version="1.0" encoding="UTF-8"?>'
$batch += '<ows:Batch>'
foreach ($item in $items) {
$batch += '<Method>'
$batch += '<SetList Scope="Request">' + $list.ID + '</SetList>'
$batch += '<SetVar Name="Cmd">Delete</SetVar>'
$batch += '<SetVar Name="ID">' + $item.ID + '</SetVar>'
$batch += '<SetVar Name="owsfileref">' + $item["FileRef"] + '</SetVar>'
$batch += '</Method>'
}
$batch += '</ows:Batch>'
$web.ProcessBatchData($batch)
}
}
catch {
Write-Error $_
}
Stop-SPAssignment -Global
And I get the following error:
C:\Users\admin\Documents\scripts\scripts.ps1 : The term 'Get-SPWeb' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
Is the function deprecated? If so, what replaces it?