![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | deleting sms junk folders that require admin permission When sms fails to install package on a machine, it will create some *junk folders* eg d:\01b23a6a69662dce1aef I know how to delete it manually by the following : a) Go to folder's security tab properties and select Administrators, allow full control. b) delete it manually. Problem is there are numerous *junk folders* and the *COMMON * folder under it is "update" folder. Therefore i need to loop every folders and if detect "update" subfolder, it should delete the root folder which is eg d:\01b23a6a69662dce1aef OR d:\17aaa9a1d699800e0de905789dae4b16 At the same time, i need to ensure that i take the root junk folders and assign full permission over it and delete it. I also need to do it REMOTELY, ie delete these folders at remote pc that sms created. Any help ? |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: deleting sms junk folders that require admin permission IT STAFF wrote:
deeper like d:\something\something\deeper? Does the script need to look through all the local drives? Just to keep Brandon happy, I think you can do this with LogParser... ;-) Seriously, a combination of WinRM and PowerShell may help. Do you have both installed on the remote systems? Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||
| Guest | Re: deleting sms junk folders that require admin permission The directory structure is d:\something\update LogParser ? I've ctp v2 of powershell ...do i need to install winrm in EVERY remote machine OR just install winrm in the machine that runs the script ?
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: deleting sms junk folders that require admin permission On Jun 27, 1:02*pm, "IT STAFF" <jkk...@xxxxxx> wrote:
Doable with wmi and .Net You will need to have admin rights on the remote machine # Get a ACL from an object you have full permission on $permission = Get-ACL -Path "DIR_TO_COPY_PERMMISSIONS_FROM" #Assign a computername to a variable $comp = "COMPUTERYOUNEEDTOCLEAN" #Get the list of directories from the computer $directory = Get-WMIObject -ComputerName $comp -Query {SELECT DeviceID FROM Win32_LogicalDisk WHERE DriveType='3'} | Select DeviceID | Foreach-Object {$_.DeviceID.Replace(":", "$")} | Foreach- Object{[System.IO.Directory]::GetDirectories("\\$comp\$_")} | Where- Object {!$_.Contains("System Volume Information")} | Foreach-Object{$_, [System.IO.Directory]::GetDirectories("$_", "UPDATE", [System.IO.SearchOption]::AllDirectories)} | Foreach- Object{[System.IO.Directory]::GetParent($_)} #For each directory, take ownership $directory | Foreach-Object {$_.GetAccessControl().setowner($permission.GetOwner([System.Security.Principal.NTAccount]))} #copy permissions foreach($dir in $directory) {Set-Acl $dir -AclObject $permission} #Delete the directory Remove the -whatif after you test it $directory | Foreach-Object {del $_.FullName -Whatif} Hope that helps a little bit, I'll try to come back and explain further if you can't follow it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | #5 (permalink) | ||||||||||||
| Guest | Re: deleting sms junk folders that require admin permission
performance aspect. I'll have to try it. Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com | ||||||||||||
My System Specs![]() | |||||||||||||
| | #6 (permalink) | ||||||||||||
| Guest | Re: deleting sms junk folders that require admin permission
may not be an option... Marco | ||||||||||||
My System Specs![]() | |||||||||||||
| | #7 (permalink) |
| Guest | Re: deleting sms junk folders that require admin permission $directory = Get-WMIObject -ComputerName $comp -Query {SELECT DeviceID FROM Win32_LogicalDisk WHERE DriveType='3'} | Select DeviceID | Foreach {$_.DeviceID.Replace(":", "$")} | Foreach {[System.IO.Directory]::GetDirectories("\\$comp\$_")} | Where {!$_.Contains("System Volume Information")} |Foreach {$_,[System.IO.Directory]::GetDirectories("$_", "UPDATE",[System.IO.SearchOption]::topdirectoryonly)} $directory | Foreach {[System.IO.Directory]::GetParent($_)} Error : "Path cannot be the empty string or all whitespace. =================================== "Sorry if this is a bit hard to read, kinda in a hurry Doable with wmi and .Net You will need to have admin rights on the remote machine # Get a ACL from an object you have full permission on $permission = Get-ACL -Path "DIR_TO_COPY_PERMMISSIONS_FROM" #Assign a computername to a variable $comp = "COMPUTERYOUNEEDTOCLEAN" #Get the list of directories from the computer $directory = Get-WMIObject -ComputerName $comp -Query {SELECT DeviceID FROM Win32_LogicalDisk WHERE DriveType='3'} | Select DeviceID | Foreach-Object {$_.DeviceID.Replace(":", "$")} | Foreach- Object{[System.IO.Directory]::GetDirectories("\\$comp\$_")} | Where- Object {!$_.Contains("System Volume Information")} | Foreach-Object{$_, [System.IO.Directory]::GetDirectories("$_", "UPDATE", [System.IO.SearchOption]::AllDirectories)} | Foreach- Object{[System.IO.Directory]::GetParent($_)} #For each directory, take ownership $directory | Foreach-Object {$_.GetAccessControl().setowner($permission.GetOwner([System.Security.Principal.NTAccount]))} #copy permissions foreach($dir in $directory) {Set-Acl $dir -AclObject $permission} #Delete the directory Remove the -whatif after you test it $directory | Foreach-Object {del $_.FullName -Whatif} Hope that helps a little bit, I'll try to come back and explain further if you can't follow it. |
My System Specs![]() |
| | #8 (permalink) |
| Guest | Re: deleting sms junk folders that require admin permission Let me try to explain this a bit better. # Get a ACL from an object you have full permission on $permission = Get-ACL -Path "DIR_TO_COPY_PERMMISSIONS_FROM" #Assign a computername to a variable this should be the computer you need to target as a string ie "FX354-QR421" $comp = "COMPUTERYOUNEEDTOCLEAN" #Get the list of directories from the computer #First get a list of all fixed hdd in the computer using wmi $directory = Get-WMIObject -ComputerName $comp -Query {SELECT DeviceID FROM Win32_LogicalDisk WHERE DriveType='3'} | #Grab only the device ID "C:" "D:" etc Select DeviceID | #Foreach Drive Replace the : with a $ Foreach-Object {$_.DeviceID.Replace(":", "$")} | #Foreach drive use .Net class to search only top Directories so we can #filter out the System Volume Information since only the OS hass access to this folder Foreach-Object{[System.IO.Directory]::GetDirectories("\\$comp\$_")} | Where-Object {!$_.Contains("System Volume Information")} | # Foreach top level directory search recursively for a folder named "UPDATE" Foreach-Object{$_, [System.IO.Directory]::GetDirectories("$_", "UPDATE", [System.IO.SearchOption]::AllDirectories)} | # Foreach "UPDATE" Directory get the parent directory and store it in the $directory variable Foreach-Object{[System.IO.Directory]::GetParent($_)} #For each directory, take ownership $directory | Foreach-Object {$_.GetAccessControl().setowner($permission.GetOwner([System.Security.Princ* ipal.NTAccount]))} #copy permissions foreach($dir in $directory) {Set-Acl $dir -AclObject $permission} #Delete the directory Remove the -whatif after you test it $directory | Foreach-Object {del $_.FullName -Whatif} The only idea i have at the moment is that you have an UPDATE folder directly under the root drive. From you post above that shouldn't be the case though. I would say try to set the $permission variable and $computername variable then start inputting that big pipeline one step at a time. Check $directory before you add another pipe. ie set vars then run $directory = Get-WMIObject -ComputerName $comp - Query {SELECT DeviceID FROM Win32_LogicalDisk WHERE DriveType='3'} view $directory then add the next part of the pipe view $directory etc... It's working allright when i build a C:\a9y4bag897ay890ag\UPDATE directory on a remote box then remove my permissions from it. Its able to delete it with no problem. Let me know if it works out for you. |
My System Specs![]() |
| | #9 (permalink) |
| Guest | Re: deleting sms junk folders that require admin permission Let me try and get back to u on this. I am looking at directories that only have "update" at the 2nd level. Thus i wish to cut down on the search. Also i prefer to look at d:\ drive rather than all hard-drive eg c:\ Any "update" folder at deeper level, i will not be deleting. "Kuma" <kumasan76@xxxxxx> wrote in message news:bd992d0e-fd02-4974-99b4-6f84da633a42@xxxxxx Let me try to explain this a bit better. # Get a ACL from an object you have full permission on $permission = Get-ACL -Path "DIR_TO_COPY_PERMMISSIONS_FROM" #Assign a computername to a variable this should be the computer you need to target as a string ie "FX354-QR421" $comp = "COMPUTERYOUNEEDTOCLEAN" #Get the list of directories from the computer #First get a list of all fixed hdd in the computer using wmi $directory = Get-WMIObject -ComputerName $comp -Query {SELECT DeviceID FROM Win32_LogicalDisk WHERE DriveType='3'} | #Grab only the device ID "C:" "D:" etc Select DeviceID | #Foreach Drive Replace the : with a $ Foreach-Object {$_.DeviceID.Replace(":", "$")} | #Foreach drive use .Net class to search only top Directories so we can #filter out the System Volume Information since only the OS hass access to this folder Foreach-Object{[System.IO.Directory]::GetDirectories("\\$comp\$_")} | Where-Object {!$_.Contains("System Volume Information")} | # Foreach top level directory search recursively for a folder named "UPDATE" Foreach-Object{$_, [System.IO.Directory]::GetDirectories("$_", "UPDATE", [System.IO.SearchOption]::AllDirectories)} | # Foreach "UPDATE" Directory get the parent directory and store it in the $directory variable Foreach-Object{[System.IO.Directory]::GetParent($_)} #For each directory, take ownership $directory | Foreach-Object {$_.GetAccessControl().setowner($permission.GetOwner([System.Security.Princ* ipal.NTAccount]))} #copy permissions foreach($dir in $directory) {Set-Acl $dir -AclObject $permission} #Delete the directory Remove the -whatif after you test it $directory | Foreach-Object {del $_.FullName -Whatif} The only idea i have at the moment is that you have an UPDATE folder directly under the root drive. From you post above that shouldn't be the case though. I would say try to set the $permission variable and $computername variable then start inputting that big pipeline one step at a time. Check $directory before you add another pipe. ie set vars then run $directory = Get-WMIObject -ComputerName $comp - Query {SELECT DeviceID FROM Win32_LogicalDisk WHERE DriveType='3'} view $directory then add the next part of the pipe view $directory etc... It's working allright when i build a C:\a9y4bag897ay890ag\UPDATE directory on a remote box then remove my permissions from it. Its able to delete it with no problem. Let me know if it works out for you. |
My System Specs![]() |
| | #10 (permalink) | ||||||||||||
| Guest | Re: deleting sms junk folders that require admin permission On Jun 27, 10:48*am, "IT STAFF" <jkk...@xxxxxx> wrote:
AllDirectories [System.IO.SearchOption]::AllDirectories not [System.IO.SearchOption]::TopDirectoryOnly | ||||||||||||
My System Specs![]() | |||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| For ITStaff Reply for deleting junk folders | Kuma | PowerShell | 0 | 07-08-2008 03:30 AM |
| Several programs require Permission | paroots | Vista General | 5 | 04-13-2008 08:10 AM |
| Setting process priority on applications that require Run as Admin | Aidan Chalk | Vista performance & maintenance | 2 | 02-13-2008 03:04 PM |
| Re: Running 3rd party apps that require admin privs on Vista | PA Bear [MS MVP] | Vista security | 1 | 01-25-2008 05:15 PM |
| Adjust font size (DPI) does not require admin privs | Marco | Vista security | 1 | 07-01-2006 01:21 AM |