-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteFiles.ps1
More file actions
49 lines (37 loc) · 1.31 KB
/
DeleteFiles.ps1
File metadata and controls
49 lines (37 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Created Simon Meredith September 2016
#Had to grant permissions first using the following:
#$w = Get-SPWebApplication -Identity https://*************************
#$w.GrantAccessToProcessIdentity("domain\username")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
#Site Collection where you want to delete files
$siteCollUrl = "https://******************************************"
#Document Library from which you want to delete the file
$libraryName = "Rotation Grids"
#Get the site collection object
$Web = Get-SPWeb $siteCollUrl;
#Get the list object
$spList = $Web.Lists[$libraryName];
#Check destination list exists
if($spList -eq $null)
{
Write-Host "The Library $libraryName could not be found."
return;
}
$choice = ""
while ($choice -notmatch"[y/n]")
{
$choice = read-host "Are you sure you want to delete all files in $($libraryName)? (Enter Y/N)"
}
if ($choice -eq "y")
{
$files = $spList.Items | where {$_.FileSystemObjectType -eq "File"}
foreach ($file in $files)
{
Write-Output "Deleting file $($file.name)..."
$file.Delete()
}
}
else {write-host "Aborting delete script"}