![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | trouble with a powershell script i have a simple litte script in which i am trying to delete all the contents of a bunch of directories (not the directories themselves). it worked fine in my testing - but when i try to run it against the actual folders, i get an error: Not Enough permission to perform operation. i am logged on as an admin and can manually delete the files/folders. I am assuming that there is some context issues or something. I am using PowerGUI. here is the main code ForEach ($HomeFolder in dir $Basepath) {` $delPath = $homefolder.FullName + "\*" write-host $delPath Remove-Item $delpath -recurse } any thoughts thanks bj |
| | #2 (permalink) | ||||||||||||
| Guest | Re: trouble with a powershell script Seems there are some read-only files in one or more directories, try to add -force to remove-item. Also, you'll probably get another error, like: An object at the specified path <path to file> does not exist. That's because your dir include files and you are appending "\*" to each file found. To fix it, include directories only (e.g. $_.PSIsContainer): ForEach ($HomeFolder in (dir $Basepath | where {$_.PSIsContainer})){ $delPath = $homefolder.FullName write-host $delPath Remove-Item $delpath -recurse } --- Shay Levy Windows PowerShell MVP blog: http://blogs.microsoft.co.il/blogs/ScriptFanatic
| ||||||||||||
| | #3 (permalink) | ||||||||||||
| Guest | Re: trouble with a powershell script <bj.daniels.0000@xxxxxx> wrote in message news:ba232cee-8296-4322-84db-a1d4b34b135d@xxxxxx
You'd also need to be careful not to delete subfolders along with the files (which you will do with a blanket Remove-Item -Recurse .... statement). Something like this would avoid that by focussing just on files .... dir $BasePath -Force -Recurse | ` where {Test-Path $_.FullName -PathType Leaf} | ` Remove-Item -Force -- Jon | ||||||||||||
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Powershell script help | Tboz | PowerShell | 3 | 4 Weeks Ago 08:58 AM |
| when run powershell script as windows service ,powershell fail | powershell fail on winodws 2008 | PowerShell | 6 | 01-15-2008 03:20 PM |
| PowerShell script using PowerSMO | Marco Shaw | PowerShell | 0 | 09-25-2007 08:06 AM |
| trouble running a script | BJ Daniels | PowerShell | 3 | 08-20-2007 03:10 PM |
| How to schedule a Powershell script?? | jim | PowerShell | 5 | 10-19-2006 10:15 PM |