-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemove-Files.ps1
More file actions
37 lines (24 loc) · 981 Bytes
/
Copy pathRemove-Files.ps1
File metadata and controls
37 lines (24 loc) · 981 Bytes
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
#Remove files remotely
function Remove-Files {
param (
[string]$Computer,
[string]$Dir
)
net use \\$Computer /user:"$($env:USERDOMAIN)\$($env:USERNAME)"
$remotePath = "\\$Computer\$Dir"
$directoryContents = Get-ChildItem -Path $remotePath
Write-Host "Contents of directory '$remotePath':"
for ($i = 0; $i -lt $directoryContents.Count; $i++) {
Write-Host "$i. $($directoryContents[$i].Name)"
}
Write-Host ""
$selection = Read-Host "Enter the number of the file to delete"
if ($selection -ge 0 -and $selection -lt $directoryContents.Count) {
$fileToDelete = $directoryContents[$selection]
Remove-Item -Path (Join-Path -Path $remotePath -ChildPath $fileToDelete.Name) -Force
Write-Host "File '$($fileToDelete.Name)' has been deleted."
} else {
Write-Host "Invalid selection."
}
net use /delete \\$Computer\$shareName
}