I am trying to delete some files in:
C:\inetpub\wwwroot\my_site\
Under
my_site, there are many files and folders, including bin folders which has some .dll files. As soon as I run the script, I get an error message that some of the .dll files cannot be accessed because they are being used by another process, and on some dlls, I get a permission denied error.I don't know what the problem is. I am using the following script, which works perfect for any other folders, but not for the one I am trying to delete.
$content = get-childitem 'C:\Backups\my_site' $sortedContent = $content | Sort-Object LastWriteTime -Descending write-host "This is the list of all the backups for my_site :" $count = 1 foreach ($item in $sortedContent) { Write-Host ("{0}: {1}" -f $count, $item.Name) $count++ } # 2.Take input from user $itemNumber = Read-Host "Please select which backup you want to restore" $confirmation = Read-Host "Are you Sure You Want To Proceed:" # 2.Take input from user if ($confirmation -eq 'y') { # 3. BACKUP script ./bacup_mysite.ps1 # 3. BACKUP # 4. DELETE CONTENTS OF my_site get-childitem "C:\inetpub\wwwroot\my_site\" -recurse | % { remove-item $_.FullName -recurse -force } } # 4. DELETE CONTENTS OF APP # 5. COPY CONTENTS OF ZIP INTO APP DIRECTORY $itemNumber = $itemNumber -1 if($sortedContent[$itemNumber].PSIsContainer -eq $true) { $src = $sortedContent[$itemNumber].FullName + "\" $WebzipPath = $src + "my_site.zip" $Date = Get-Date $folder_date = $Date.ToString("yyyy-MM-dd_HHmm") $tempPath = 'C:\_Temp\Restore\my_site_restore_' + $folder_date if (!(Test-Path -path $tempPath)) { New-Item $tempPath -type directory } ./Library/unzip.ps1 $WebzipPath $tempPath $tempPathWeb = $tempPath + "/my_site/*" Copy-Item -Path $tempPat -Destination 'C:\inetpub\wwwroot\my_site\' -Recurse - force
↧
Files cannot access because they are used by another process
↧